天天看點

Linux下安裝Supersetpython3下:Was unable to import superset Error: No module named 'MySQLdb'superset權限控制

1、安裝python3

Anaconda3-2019.03-Linux-x86_64.sh

2、安裝superset依賴包

yum install gcc gcc-c++ libffi-devel python-devel python-pip python-wheel openssl-devel libsasl2-devel openldap-devel

3、在virtualenv環境下安裝Superset, 這樣可以避免Python版本沖突

(1)安裝virtualenv

pip install virtualenv

(2)建立ven環境

virtualenv venv

(3)激活ven環境

. ./venv/bin/activate

(4)如果要退出該環境則執行:

deactivate

4、安裝Superset

(1)安裝Superset

pip install superset

(2)建立管理者使用者名和密碼

fabmanager create-admin --app superset

報錯資訊:

Linux下安裝Supersetpython3下:Was unable to import superset Error: No module named 'MySQLdb'superset權限控制

解決方案:pip install pandas==0.23.4

Linux下安裝Supersetpython3下:Was unable to import superset Error: No module named 'MySQLdb'superset權限控制

(3)初始化Superset

superset db upgrade

報錯資訊:

Linux下安裝Supersetpython3下:Was unable to import superset Error: No module named 'MySQLdb'superset權限控制

解決方案:pip install SQLAlchemy==1.2.18

Linux下安裝Supersetpython3下:Was unable to import superset Error: No module named 'MySQLdb'superset權限控制
Linux下安裝Supersetpython3下:Was unable to import superset Error: No module named 'MySQLdb'superset權限控制

(4)裝載初始化樣例資料

superset load_examples

(5)建立預設角色和權限

superset init

(6)啟動Superset

superset runserver -d -p 8088

(7) 通路http://ip:8088, 驗證是否正常啟動,如出現下面頁面說明OK

2、漢化Superset

1、首先superset有自己的翻譯目錄,不用建立,目錄為:

~/superset/superset/translations

2、要漢化的話,配置檔案

~/superset/superset/translations/zh/LC_MESSAGES/messages.po

即可.

3、修改config.py的配置,如下:

BABEL_DEFAULT_LOCALE = 'zh'     BABEL_DEFAULT_FOLDER = '/home/hadoop/superset/superset/translations'     LANGUAGES = {       #'en': {'flag': 'us', 'name': 'English'},       # 'fr': {'flag': 'fr', 'name': 'French'},        'zh': {'flag': 'cn', 'name': 'Chinese'},   }

4、編譯messages.po檔案:

cd ~/superset/superset/translations/zh/LC_MESSAGES   msgfmt ./messages.po -o ./messages.mo

5、重新開機浏覽器, 即可(不行就清楚緩存)

參考:https://segmentfault.com/a/1190000015811094

配置kylin資料源:

測試連接配接時,報錯資訊:

ERROR: {"error": "Connection failed!\n\nThe error message returned was:\nCan't load plugin: sqlalche

解決 : pip3 install kylinpy

配置mysql:

配置superset配置檔案,config.py

SQLALCHEMY_DATABASE_URI = ‘mysql://root:密碼@ip/superset?charset=utf8’

在mysql資料庫中建立superset資料庫:create database superset;

python3下:Was unable to import superset Error: No module named 'MySQLdb'

分析:

MySQLdb隻支援Python2.*,還不支援3.*.可以用PyMySQL代替

解決:
           

1、安裝mysql

pip install PyMySQL --trusted-host pypi.douban.com

2、修改mysql連結的__init__.py

/root/anaconda3/lib/python3.7/site-packages/superset/__init__.py

import pymysql

pymysql.install_as_MySQLdb()

看網上有的說是改:

/root/anaconda3/lib/python3.7/site-packages/sqlalchemy/dialects/mysql/__init__.py

fabmanager create-admin --app superset

 superset db upgrade

superset init

superset runserver

Linux下安裝Supersetpython3下:Was unable to import superset Error: No module named 'MySQLdb'superset權限控制

pymysql.err.InternalError: (1366, "Incorrect string value: '\\xE6\\x9C\\xAA\\xE5\\x91\\xBD...' for column 'tab_name' at row 1")

檢視了下query表的tab_name字段為空,說明資料沒有插入進去,根據錯誤資訊說tab_name的值不對,值的編碼格式不對導緻報這錯誤;

Linux下安裝Supersetpython3下:Was unable to import superset Error: No module named 'MySQLdb'superset權限控制

解決方案:修改表的編碼方式--utf8

alter table `query` convert to character set utf8

再次運作就沒有報錯--》

Linux下安裝Supersetpython3下:Was unable to import superset Error: No module named 'MySQLdb'superset權限控制

superset權限控制

public權限

圖表嵌入html中報權限錯誤:{“error”: “This endpoint requires the datasource birth_names, database or\n all_datasource_access permission”}

解決: 在 superset/config.py 配置GAMMA權限,并且登陸web控制台(安全–>角色清單–> 選擇public: 編輯記錄–> 搜尋all_datasource_access, 添加相關的選項,儲存退出即可)

# ---------------------------------------------------
# Roles config
# ---------------------------------------------------
# Grant public role the same set of permissions as for the GAMMA role.
# This is useful if one wants to enable anonymous users to view
# dashboards. Explicit grant on specific datasets is still required.
PUBLIC_ROLE_LIKE_GAMMA = TRUE
           

檢視dashboard權限

安全—> 角色清單–>找到對應的角色: 添權重限

can dashboard on Superset   
can explore json on Superset