tableau 連接python

最簡單的方式就是裝一個現成的環境,anaconda,在裏面安裝兩個包

在C盤中搜索startup.bat,放在桌面比較方便,運行彈出此界面即可。

 

Done!!!

參考資料1:https://onlinehelp.tableau.com/current/api/extract_api/en-us/Extract/extract_api_using_python.htm

Using the Extract API 2.0 with Python

This topic describes how to install the Extract API for Python and how to reference the Extract API library in Python code.

Note: To perform these steps, you must run as a user who has administrator access.

  1. Extract the Python package that you downloaded into a directory on your computer. For details, see Installing the Extract API 2.0.

  2. At the command line, go to the directory where you extracted the package.

  3. Open a command window as a root or administrator user.

  4. On a Windows computer, run the following commands:

    python setup.py build
    python setup.py install

    On a Linux or Apple computer, use the following commands:

    sudo python setup.py install

    After entering the sudo command, you might be asked to enter your password.

  5. In your Python code, import the API that you want to work with using syntax like this:

    from tableausdk import *
    from tableausdk.HyperExtract import *

參考資料2:http://blog.sina.com.cn/s/blog_af8b11b50102xap5.html

一、Python編譯器安裝

Python編譯器以pycharm爲例,下載方式和安裝的方法不再介紹。 

二、Tabpy-Server環境搭建

在Tableau公司的Github主頁下,有一個名爲Tabpy的項目,提供了Tableau和Python集成的套件:Tabpy framework。

GitHub下載地址:https://github.com/tableau/TabPy

Tabpy Server安裝方法有兩種:

(1)官方提供了一個整體打包的方案,可以從GitHub頁面下載整個項目到本地,點擊setup.bat或setup.sh文件就可以自動下載Anaconda環境,創建一個名爲Tableau-Python-Server的環境,並且在這個環境中安裝好Tabpy及相關的各種庫。

(2)也可以手動安裝,手動安裝的步驟如下(以Windows平臺爲例):

a)本機下載安裝Anaconda,把Anaconda的Python環境加入到環境變量;

b)運行以下命令在Anaconda上建立一個名爲Tableau-Python-Server的環境,在本機搜索程序Anaconda Prompt點擊進入,在此命令框輸入命令(可指定Python的版本):

conda create --name Tableau-Python-Server python=2.7 anaconda

c) 運行以下命令切換到新創建的環境:

activate Tableau-Python-Server

然後運行命令安裝Tabpy

pip install tabpy-server

如果命令運行一切正常,你可以在anaconda安裝目錄中進行查看是否存在啓動選項,在路徑...\anaconda\envs\Tableau-Python-Server\Lib\site-packages下看到一個名爲tabpy_server的文件夾,裏面包含了一個用於啓動Tabpy server的startup.bat文件,可以把它創建一個快捷方式到你的桌面,以後你會需要經常點擊它啓動Tabpy Server。

截至目前,就可以啓動Tabpy Server,打開tableau然後在外部服務器中配置本地IP和端口9004,然後在計算字段中寫python代碼了。

三、PyCharm修改默認運行環境

打開PyCharm,點擊File—Settings—Project —Project Interpreter可以進入如圖的界面,可以選擇Existing environment選擇TabPy中的Python環境,根據自己的安裝位置,地址大致是:...\Anaconda3\envs\Tableau-Python-Server\python.exe。選擇後確定即可。

到此爲止,在PyCharm中運行Python代碼就發佈到了Tabpy-server中,Tableau中使用計算字段就可以調用。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章