天天看点

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