安装
安装依赖
1 |
<span class="n">sudo</span> <span class="n">apt</span><span class="o">-</span><span class="n">get</span> <span class="n">install</span> <span class="n">build</span><span class="o">-</span><span class="n">essential</span> <span class="n">libssl</span><span class="o">-</span><span class="n">dev</span> <span class="n">libffi</span><span class="o">-</span><span class="n">dev</span> <span class="n">libsasl2</span><span class="o">-</span><span class="n">dev</span> <span class="n">libldap2</span><span class="o">-</span><span class="n">dev libmysqlclient-dev</span> |
安装 Python
1 2 3 4 5 6 7 8 9 10 11 12 |
mkdir -p /usr/local/python3 && cd /usr/local/python3/ wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz tar -vzxf Python-3.6.6.tgz && cd Python-3.6.6 ./configure --prefix=/usr/local/python3/Python-3.6.6 make && make install ln -s /usr/local/python3/Python-3.6.6/bin/python3.6 /usr/bin/python3 ln -s /usr/local/python3/Python-3.6.6/bin/pip3 /usr/bin/pip3 #环境配置 pip3 install virtualenv python3 -m venv venv . venv/bin/activate pip install --upgrade setuptools pip |
安装 Superset
GitHub:https://github.com/apache/incubator-superset
文档:https://superset.incubator.apache.org/installation.html
1 2 3 4 5 6 |
pip install superset fabmanager create-admin --app superset // flask fab create-admin superset db upgrade superset load_examples superset init superset runserver -d |
数据表操作
1 2 3 4 5 |
sudo apt-get install sqlite3 cd ~/.superset sqlite3 .open superset.db .tables |
根据所需连接数据库,需安装相同的 PyPi 包,如 MySQL:pip install mysqlclient,其它的请参见官方文档
- 进入 Sources > Databases,点击添加,输入名称,SQLAlchemy URI:mysql://user:passwd@xxx.xxx.xxx.xxx/db_name
- 进入 Sources > Tables,点击添加,选择数据库,并填写数据表名
- 进入 Charts,点击添加,选择数据源及可视化类型
添加配置文件
1 2 3 |
touch ~/.superset/superset_config.py echo 'export SUPERSET_CONFIG_PATH=$HOME/.superset/superset_config.py' >> ~/.bash_profile source ~/.bash_profile |
所有配置项参见:https://github.com/apache/incubator-superset/blob/master/superset/config.py
1 2 3 |
# 获取地址:https://docs.mapbox.com/help/how-mapbox-works/access-tokens/ MAPBOX_API_KEY= os.environ.get('MAPBOX_API_KEY', 'mapbox-api-key') SECRET_KEY = 'xxxxxxxx' |
将 sqlite3切换迁移为 PostgreSQL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
sudo apt-get install libpq-dev pip install psycopg2 # 安装 PostgreSQL sudo apt-get -y install postgresql postgresql-client postgresql-contrib # 创建数据库、用户和密码 sudo su postgres cd ~ psql create database superset; CREATE USER superset WITH PASSWORD 'superset'; GRANT ALL PRIVILEGES ON DATABASE "superset" to superset; \q # 设置密码为 md5加密 sudo vi /etc/postgresql/9.6/main/pg_hba.conf # 相应内容替换为 local all superset md5 # 重启服务 sudo service postgresql restart # 修改配置文件对应部分为 SQLALCHEMY_DATABASE_URI = "postgressql+psycopg2://superset:password@localhost/superset" # 更新 superset db upgrade superset init #迁移 sudo apt-get install ruby-dev libpq-dev libsqlite3-dev sudo gem install pg sqlite3 sudo gem install sequel sudo sequel -C sqlite:///home/vagrant/.superset/superset.db postgresql://superset:superset@localhost/superset # 登入验证 psql -U superset \dt # 缓存设置 sudo apt-get install redis-server sudo systemctl restart redis-server.service sudo systemctl enable redis-server.service # 配置文件 CACHE_CONFIG={ # Specify the cache type'CACHE_TYPE':'redis', 'CACHE_REDIS_URL':'redis://localhost:6379/0', # The key prefix for the cache values stored on the server 'CACHE_KEY_PREFIX':'superset_results' } |
常见问题
1、subprocess.CalledProcessError: Command ‘(‘lsb_release’, ‘-a’)’ returned non-zero exit status 1.
查看lsb_release.py所在目录
1 |
sudo find / -name 'lsb_release.py' |
将对应的lsb_release.py文件拷贝到subprocess.py目录下,如:
1 |
sudo cp /usr/lib/python3/dist-packages/lsb_release.py /usr/local/python3/Python-3.6.6/lib/python3.6/ |
2、Was unable to import superset Error: No module named ‘_sqlite3’
1 2 3 4 5 6 7 |
sudo apt-get install libsqlite3-dev cd /usr/local/python3/Python-3.6.6/ ./configure make && make install # CentOS yum instlal sqlite-devel |
3、 Was unable to import superset Error: cannot import name ‘_maybe_box_datetimelike’
安装更低版本的 pandas
1 2 |
pip uninstall pandas pip install pandas==0.23 |
4、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.
在执行superset db upgrade是发生的报错,需安装低版本sqlalchemy
1 2 |
pip uninstall sqlalchemy pip install sqlalchemy==1.2 |
5、OSError: mysql_config not found
1 |
sudo apt-get install libmysqlclient-dev python3-dev |