Anaconda 安裝和配置
1. Anaconda 安裝
Anaconda說明及安裝過程:Anaconda詳細安裝使用教程
Anaconda環境變量配置:配置環境變量
2. Anaconda和Pip源修改
- Anaconda源修改:打開Anaconda Prompt后,輸入以下代碼。
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --set show_channel_urls yes
- Pip源修改:在本地User用戶目錄新建pip目錄,然后新建pip.ini文件,編輯如下代碼后保存。
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple
3. Anaconda常用命令
3.1 模塊遷移
- 將當前環境安裝的所有模塊信息導出到名為requirements.txt文件中,該文件存放在當前用戶目錄下。
pip freeze > requirements.txt
- 新環境中根據requirements.txt文件來安裝模塊。
pip install -r C:\Users\XXX\requirements.txt
3.2 環境創建、激活和退出
- 創建環境
conda create -n env_name package_name=version
- 激活環境
(base) C:\Users\Administrator>activate superset
(superset) C:\Users\Administrator>
- 列出環境
(base) C:\Users\Administrator>conda env list # conda environments: # base * D:\ProSoftwares\Python\Anaconda3 python36 D:\ProSoftwares\Python\Anaconda3\envs\python36 superset D:\ProSoftwares\Python\Anaconda3\envs\superset
- 退出環境
(superset) C:\Users\Administrator>conda deactivate (base) C:\Users\Administrator>
3.3 克隆環境
使用該方法,可以重命名環境:
(base) C:\Users\Administrator>conda create -n analysis --clone python36
然后刪除原來的環境即可:
(base) C:\Users\Administrator>conda remove -n python36 --all
4. Anaconda安裝superset環境(在線)
4.1 創建隔離環境
(base) C:\Users\Administrator>conda activate -n superset python==3.6
創建一個隔離環境,防止和其它環境的包發生沖突。
4.2 安裝VC++需求文件
進入superset環境后,嘗試用pip install superset命令直接安裝,最后提示Failed to build superset python-geohash錯誤,缺少編譯環境,並提示下載:
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
上述下載地址失效,使用VC++14.0安裝教程進行安裝。安裝完成后,重新使用pip install superset命令安裝superset,則可正常安裝:
Successfully installed cchardet-2.1.4 et-xmlfile-1.0.1 ijson-2.3 jdcal-1.4.1 jsonlines-1.2.0 linear-tsv-1.1.0 openpyxl-2.4.11 pure-sasl-0.6.1 python-geohash-0.8.5 rfc3986-1.3.1 simplejson-3.16.0 sqlalchemy-utils-0.33.11 sqlparse-0.3.0 superset-0.28.1 tableschema-1.4.1 tabulator-1.20.0 thrift-0.11.0 thrift-sasl-0.3.0 unicodecsv-0.14.1 unidecode-1.0.23 xlrd-1.2.0
4.3 配置superset
- 創建superset管理員賬號
(superset) C:\Users\Administrator>fabmanager create-admin --app superset fabmanager is going to be deprecated in 2.2.X, you can use the same commands on the improved 'flask fab <command>' Username [admin]: admin User first name [admin]: Strive User last name [user]: Py Email [admin@fab.org]: strive@qq.com Password: Repeat for confirmation: Was unable to import superset Error: cannot import name '_maybe_box_datetimelike'
出現Was unable to import superset Error: cannot import name '_maybe_box_datetimelike'錯誤,原因是pandas版本(0.24.2)太高,卸載重裝0.23.4版本:
pip uninstall pandas pip install pandas==0.23.4
再進行管理員賬號創建:
(superset) C:\Users\Administrator>fabmanager create-admin --app superset fabmanager is going to be deprecated in 2.2.X, you can use the same commands on the improved 'flask fab <command>' Username [admin]: admin User first name [admin]: Strive User last name [user]: Py Email [admin@fab.org]: strive@qq.com Password: Repeat for confirmation: Recognized Database Authentications. Admin User admin created.
-
初始化數據庫需要使用python superset命令,該命令需要進入superset包的bin目錄(D:\ProSoftwares\Python\Anaconda3\envs\superset\Lib\site-packages\superset\bin)下執行:
(superset) D:\ProSoftwares\Python\Anaconda3\envs\superset\Lib\site-packages\superset\bin>python superset Usage: superset [OPTIONS] COMMAND [ARGS]... This is a management script for the superset application. Options: --version Show the flask version --help Show this message and exit. Commands: db Perform database migrations. export_dashboards Export dashboards to JSON export_datasource_schema Export datasource YAML schema to stdout export_datasources Export datasources to YAML fab FAB flask group commands flower Runs a Celery Flower web server Celery Flower... import_dashboards Import dashboards from JSON import_datasources Import datasources from YAML init Inits the Superset application load_examples Loads a set of Slices and Dashboards and a... load_test_users Loads admin, alpha, and gamma user for... refresh_druid Refresh druid datasources run Runs a development server. runserver Starts a Superset web server. shell Runs a shell in the app context. update_datasources_cache Refresh sqllab datasources cache version Prints the current version number worker Starts a Superset worker for async SQL query...
- 使用python superset db upgrade命令更新數據庫,出現sqlalchemy.exc.InvalidRequestError: Can't determine which FROM clause to join from, there are multiple FROMS which can join to this entity. Try adding an explicit ON clause to help resolve the ambiguity.錯誤,原因是sqlalchemy包版(1.3.3)本太高,卸載重裝1.2.0版本,就可以成功進行數據庫更新操作。
- 使用python superset load_examples命令加載樣例模板。
- 使用python superset init命令初始化用戶角色和權限。
- 使用python superset runserver 命令啟動服務報錯,原因是superset使用gunicorn作為應用程序服務器,而gunicorn不支持windows,命令行中添加-d,使用development web server運行。最終運行命令為:python superset runserver -d。
最后在瀏覽器中訪問:localhost:8088就可以打開superset登錄頁面。
4.4 Superset數據庫查詢報錯
因為superset是為Linux和Mac服務的,Windows下缺失某些系統依賴包,所以進行數據庫查詢時,會提示'Module 'signal' has no attribute 'SIGALRM',並且查詢不到數據,解決辦法是修改superset安裝目錄下的utils.py(D:\ProSoftwares\Python\Anaconda3\envs\superset\Lib\site-packages\superset\utils.py)文件中關於signal提示的代碼。用文本編輯器打開utils.py,找到如下代碼:
def __enter__(self): try: signal.signal(signal.SIGALRM, self.handle_timeout) signal.alarm(self.seconds) except ValueError as e: logging.warning("timeout can't be used in the current context") logging.exception(e) def __exit__(self, type, value, traceback): try: signal.alarm(0) except ValueError as e: logging.warning("timeout can't be used in the current context") logging.exception(e)
然后將代碼修改為:
def __enter__(self): try: # signal.signal(signal.SIGALRM, self.handle_timeout) # signal.alarm(self.seconds) pass except ValueError as e: logging.warning("timeout can't be used in the current context") logging.exception(e) def __exit__(self, type, value, traceback): try: # signal.alarm(0) pass except ValueError as e: logging.warning("timeout can't be used in the current context") logging.exception(e)
然后刷新superset即可。
5 Anaconda安裝Superset環境(離線)
由於在線安裝出現的問題太多,所以采取離線手動安裝的方式。
5.1 使用Pip安裝依賴包
在Github源碼中找到依賴包文件requirements.txt
然后使用Pip安裝依賴包:
pip install -r C:\Users\XXX\requirements.txt
如果中途發生版本不匹配問題,修改對應包版本再繼續安裝即可。
5.2 使用Pip安裝Superset離線包
在官網下載superset-0.34.0安裝包
然后使用Pip安裝superset包:
pip install C:\Users\XXX\apache-superset-0.34.0.tar.gz
5.3 配置Superset
基本參考在線安裝,需要注意:
- 設置用戶名時不能設置admin,會提示唯一字段重復的sql錯誤。
- 啟動服務時,在bin目錄內使用命令python superset run即可。
5.4 Superset數據庫查詢報錯
因為superset是為Linux和Mac服務的,Windows下缺失某些系統依賴包,所以進行數據庫查詢時,會提示'Module 'signal' has no attribute 'SIGALRM',並且查詢不到數據,解決辦法是修改superset安裝目錄下的core.py(D:\Prosoftwares\Python\Anaconda3\envs\superset\Lib\site-packages\superset\utils\core.py)中關於signal提示的代碼(579行),按照4.4修改后,重啟服務即可。
6 參考資料
- win7+python3.6+word_cloud 安裝出現Microsoft Visual C++ 14.0 is required
- Superset的安裝配置及基礎使用手冊
- Superset創建管理員Pandas報錯