Windows Superset 填坑记

最近在了解BI和零代码相关的技术,了解到superset功能比较强大, 就打算搭一个看看,因为不想在服务器上搞,就简单在Windows上搭建了一下,没想到坑还很多,得益于网上很多朋友的经验,总算搭建完成,这里把填的坑分享一下。

参考的资料有:

轻量级BI工具Superset的搭建与使用

windows安装superset和bug排坑记 

第一步:创建python环境

我是在Anaconda3环境中搭建的,所以先构建了一个虚拟环境

打开Anaconda  Powershell Prompt 

conda create -n superset python=3.6

activate superset

创建好基于python 3.6的虚拟环境,并且切换到此环境

第二步:安装superset及其依赖

因为我已经把pip的源更换为国内源了,所以直接执行

pip install requests

pip install flask-appbuilder

pip install superset

安装过程比较顺利,并没有错误,以为一切大功告成,接下来进行superset的配置

第三步:配置superset

首先要切换到superset相关目录,网上给的资料是切换到

Anaconda3\envs\superset\Lib\site-packages\superset\bin 这个目录下

然后执行

fabmanager create-admin --app superset

这个实际是flask的工具,目前已经建议使用

flask fab create-admin

前提是先切换flask app到superset

$Env:FLASK_APP="superset"

这一个步骤创建的用户名和密码是后面登录用的用户名密码,一定要牢牢记住。

接下来执行superset数据库的初始化

superset db upgrade

INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> 4e6a06bad7a8, Init
INFO  [alembic.runtime.migration] Running upgrade 4e6a06bad7a8 -> 5a7bad26f2a7, empty message
INFO  [alembic.runtime.migration] Running upgrade 5a7bad26f2a7 -> 1e2841a4128, empty message
INFO  [alembic.runtime.migration] Running upgrade 1e2841a4128 -> 2929af7925ed, TZ offsets in data sources
INFO  [alembic.runtime.migration] Running upgrade 2929af7925ed -> 289ce07647b, Add encrypted password field
INFO  [alembic.runtime.migration] Running upgrade 289ce07647b -> 1a48a5411020, adding slug to dash
INFO  [alembic.runtime.migration] Running upgrade 1a48a5411020 -> 315b3f4da9b0, adding log model
INFO  [alembic.runtime.migration] Running upgrade 315b3f4da9b0 -> 55179c7f25c7, sqla_descr
INFO  [alembic.runtime.migration] Running upgrade 55179c7f25c7 -> 12d55656cbca, is_featured
C:\ProgramData\Anaconda3\envs\superset\lib\site-packages\alembic\ddl\sqlite.py:75: UserWarning: Skipping unsupported ALTER for creation of implicit constraintPlease refer to the batch mode feature which allows for SQLite migrations using a copy-and-move strategy.
  "Skipping unsupported ALTER for "
INFO  [alembic.runtime.migration] Running upgrade 12d55656cbca -> 2591d77e9831, user_id
INFO  [alembic.runtime.migration] Running upgrade 2591d77e9831 -> 8e80a26a31db, empty message
INFO  [alembic.runtime.migration] Running upgrade 8e80a26a31db -> 7dbf98566af7, empty message
INFO  [alembic.runtime.migration] Running upgrade 7dbf98566af7 -> 43df8de3a5f4, empty message
INFO  [alembic.runtime.migration] Running upgrade 43df8de3a5f4 -> d827694c7555, css templates
INFO  [alembic.runtime.migration] Running upgrade d827694c7555 -> 430039611635, log more
INFO  [alembic.runtime.migration] Running upgrade 430039611635 -> 18e88e1cc004, making audit nullable
INFO  [alembic.runtime.migration] Running upgrade 18e88e1cc004 -> 836c0bf75904, cache_timeouts
INFO  [alembic.runtime.migration] Running upgrade 18e88e1cc004 -> a2d606a761d9, adding favstar model
INFO  [alembic.runtime.migration] Running upgrade a2d606a761d9, 836c0bf75904 -> d2424a248d63, empty message
INFO  [alembic.runtime.migration] Running upgrade d2424a248d63 -> 763d4b211ec9, fixing audit fk
INFO  [alembic.runtime.migration] Running upgrade d2424a248d63 -> 1d2ddd543133, log dt
INFO  [alembic.runtime.migration] Running upgrade 1d2ddd543133, 763d4b211ec9 -> fee7b758c130, empty message
INFO  [alembic.runtime.migration] Running upgrade fee7b758c130 -> 867bf4f117f9, Adding extra field to Database model
INFO  [alembic.runtime.migration] Running upgrade 867bf4f117f9 -> bb51420eaf83, add schema to table model
INFO  [alembic.runtime.migration] Running upgrade bb51420eaf83 -> b4456560d4f3, change_table_unique_constraint
INFO  [alembic.runtime.migration] Running upgrade b4456560d4f3 -> 4fa88fe24e94, owners_many_to_many
INFO  [alembic.runtime.migration] Running upgrade 4fa88fe24e94 -> c3a8f8611885, Materializing permission
INFO  [alembic.runtime.migration] Running upgrade c3a8f8611885 -> f0fbf6129e13, Adding verbose_name to tablecolumn
INFO  [alembic.runtime.migration] Running upgrade f0fbf6129e13 -> 956a063c52b3, adjusting key length
INFO  [alembic.runtime.migration] Running upgrade 956a063c52b3 -> 1226819ee0e3, Fix wrong constraint on table columns
INFO  [alembic.runtime.migration] Running upgrade 1226819ee0e3 -> d8bc074f7aad, Add new field 'is_restricted' to SqlMetric and DruidMetric
INFO  [alembic.runtime.migration] Running upgrade d8bc074f7aad -> 27ae655e4247, Make creator owners
INFO  [alembic.runtime.migration] Running upgrade 27ae655e4247 -> 960c69cb1f5b, add dttm_format related fields in table_columns
INFO  [alembic.runtime.migration] Running upgrade 960c69cb1f5b -> f162a1dea4c4, d3format_by_metric
INFO  [alembic.runtime.migration] Running upgrade f162a1dea4c4 -> ad82a75afd82, Update models to support storing the queries.
INFO  [alembic.runtime.migration] Running upgrade ad82a75afd82 -> 3c3ffe173e4f, add_sql_string_to_table
INFO  [alembic.runtime.migration] Running upgrade 3c3ffe173e4f -> 41f6a59a61f2, database options for sql lab
INFO  [alembic.runtime.migration] Running upgrade 41f6a59a61f2 -> 4500485bde7d, allow_run_sync_async
INFO  [alembic.runtime.migration] Running upgrade 4500485bde7d -> 65903709c321, allow_dml
INFO  [alembic.runtime.migration] Running upgrade 41f6a59a61f2 -> 33d996bcc382, update slice model
INFO  [alembic.runtime.migration] Running upgrade 33d996bcc382, 65903709c321 -> b347b202819b, empty message
INFO  [alembic.runtime.migration] Running upgrade b347b202819b -> 5e4a03ef0bf0, Add access_request table to manage requests to access datastores.
INFO  [alembic.runtime.migration] Running upgrade 5e4a03ef0bf0 -> eca4694defa7, sqllab_setting_defaults
INFO  [alembic.runtime.migration] Running upgrade eca4694defa7 -> ab3d66c4246e, add_cache_timeout_to_druid_cluster
INFO  [alembic.runtime.migration] Running upgrade eca4694defa7 -> 3b626e2a6783, Sync DB with the models.py.
WARNI [root] Constraint must have a name
INFO  [alembic.runtime.migration] Running upgrade 3b626e2a6783, ab3d66c4246e -> ef8843b41dac, empty message
INFO  [alembic.runtime.migration] Running upgrade ef8843b41dac -> b46fa1b0b39e, Add json_metadata to the tables table.
INFO  [alembic.runtime.migration] Running upgrade b46fa1b0b39e -> 7e3ddad2a00b, results_key to query
INFO  [alembic.runtime.migration] Running upgrade 7e3ddad2a00b -> ad4d656d92bc, Add avg() to default metrics
INFO  [alembic.runtime.migration] Running upgrade ad4d656d92bc -> c611f2b591b8, dim_spec
INFO  [alembic.runtime.migration] Running upgrade c611f2b591b8 -> e46f2d27a08e, materialize perms
INFO  [alembic.runtime.migration] Running upgrade e46f2d27a08e -> f1f2d4af5b90, Enable Filter Select
INFO  [alembic.runtime.migration] Running upgrade e46f2d27a08e -> 525c854f0005, log_this_plus
INFO  [alembic.runtime.migration] Running upgrade 525c854f0005, f1f2d4af5b90 -> 6414e83d82b7, empty message
INFO  [alembic.runtime.migration] Running upgrade 6414e83d82b7 -> 1296d28ec131, Adds params to the datasource (druid) table
INFO  [alembic.runtime.migration] Running upgrade 1296d28ec131 -> f18570e03440, Add index on the result key to the query table.
INFO  [alembic.runtime.migration] Running upgrade f18570e03440 -> bcf3126872fc, Add keyvalue table
INFO  [alembic.runtime.migration] Running upgrade f18570e03440 -> db0c65b146bd, update_slice_model_json
INFO  [alembic.runtime.migration] Running upgrade db0c65b146bd -> a99f2f7c195a, rewriting url from shortner with new format
INFO  [alembic.runtime.migration] Running upgrade a99f2f7c195a, bcf3126872fc -> d6db5a5cdb5d, empty message
INFO  [alembic.runtime.migration] Running upgrade d6db5a5cdb5d -> b318dfe5fb6c, adding verbose_name to druid column
INFO  [alembic.runtime.migration] Running upgrade d6db5a5cdb5d -> 732f1c06bcbf, add fetch values predicate
INFO  [alembic.runtime.migration] Running upgrade 732f1c06bcbf, b318dfe5fb6c -> ea033256294a, empty message
INFO  [alembic.runtime.migration] Running upgrade b318dfe5fb6c -> db527d8c4c78, Add verbose name to DruidCluster and Database
INFO  [alembic.runtime.migration] Running upgrade db527d8c4c78, ea033256294a -> 979c03af3341, empty message
INFO  [alembic.runtime.migration] Running upgrade 979c03af3341 -> a6c18f869a4e, query.start_running_time
INFO  [alembic.runtime.migration] Running upgrade a6c18f869a4e -> 2fcdcb35e487, saved_queries
INFO  [alembic.runtime.migration] Running upgrade 2fcdcb35e487 -> a65458420354, add_result_backend_time_logging
INFO  [alembic.runtime.migration] Running upgrade a65458420354 -> ca69c70ec99b, tracking_url
INFO  [alembic.runtime.migration] Running upgrade ca69c70ec99b -> a9c47e2c1547, add impersonate_user to dbs
INFO  [alembic.runtime.migration] Running upgrade ca69c70ec99b -> ddd6ebdd853b, annotations
INFO  [alembic.runtime.migration] Running upgrade a9c47e2c1547, ddd6ebdd853b -> d39b1e37131d, empty message
INFO  [alembic.runtime.migration] Running upgrade ca69c70ec99b -> 19a814813610, Adding metric warning_text
INFO  [alembic.runtime.migration] Running upgrade 19a814813610, a9c47e2c1547 -> 472d2f73dfd4, empty message
INFO  [alembic.runtime.migration] Running upgrade 472d2f73dfd4, d39b1e37131d -> f959a6652acd, empty message
INFO  [alembic.runtime.migration] Running upgrade f959a6652acd -> 4736ec66ce19, empty message

这一步骤中出现大量的错误,主要是一些依赖的问题,我这边主要遇到以下依赖:

No module named 'wtforms_json'
No module named 'flask_compress'
ModuleNotFoundError: No module named 'celery'
ModuleNotFoundError: No module named 'flask_migrate'
ModuleNotFoundError: No module named 'flask_talisman'
ModuleNotFoundError: No module named 'flask_caching'
ModuleNotFoundError: No module named 'sqlparse'
ModuleNotFoundError: No module named 'bleach'
ModuleNotFoundError: No module named 'markdown'
ModuleNotFoundError: No module named 'numpy'
ModuleNotFoundError: No module named 'pandas'
ModuleNotFoundError: No module named 'parsedatetime'
ModuleNotFoundError: No module named 'pathlib2'
ModuleNotFoundError: No module named 'simplejson'
ModuleNotFoundError: No module named 'humanize'
ModuleNotFoundError: No module named 'geohash'
1、将Geohash文件夹改成geohash;
2、将文件夹下的 __init__.py 中的 from geohash 改成 from .geohash
(注意:在geohash前面多了一个点)

ModuleNotFoundError: No module named 'polyline'
ModuleNotFoundError: No module named 'geopy'
  "'cryptography' is required to use EncryptedType"
      ModuleNotFoundError: No module named 'backoff'
ModuleNotFoundError: No module named 'msgpack'
ModuleNotFoundError: No module named 'pyarrow'
ModuleNotFoundError: No module named 'contextlib2'
ModuleNotFoundError: No module named 'croniter'
ModuleNotFoundError: No module named 'retry'
ModuleNotFoundError: No module named 'selenium'
ModuleNotFoundError: No module named 'isodate'

这一步的解决思路就是缺什么补什么吧,还是比较方便的,主要就是那个geohash,需要手动改一下文件夹和init的代码。

这一步完成后就离成功一大半了,这时候其实是已经可以用了,只是没有数据,所以下一步可以用开发者提供的示例, 这个命令前面的参考文档中都是  python superset load_examples,如果发后面还会改的话,请用  python superset --help来查看,是否有其他的变化

  python superset load-examples

INFO:root:logging was configured successfully
C:\ProgramData\Anaconda3\envs\superset\lib\site-packages\flask_caching\__init__.py:202: UserWarning: Flask-Caching: CACHE_TYPE is set to null, caching is effectively disabled.
  "Flask-Caching: CACHE_TYPE is set to null, "
Loading examples metadata and related data into examples
Creating default CSS templates
Loading energy related dataset
INFO:root:Database.get_sqla_engine(). Masked URL: sqlite:///C:\Users\Administrator\.superset\superset.db
Creating table [wb_health_population] reference
Loading [World Bank's Health Nutrition and Population Stats]
Creating table [wb_health_population] reference
Creating slices
Creating a World's Health Bank dashboard
Loading [Birth names]
Done loading table!
--------------------------------------------------------------------------------
Creating table [birth_names] reference
Creating some slices
Creating a dashboard
Loading [Unicode test data]
Done loading table!
--------------------------------------------------------------------------------
Creating table [unicode_test] reference
Creating a slice
Creating a dashboard
Loading [Random time series data]
Done loading table!
--------------------------------------------------------------------------------
Creating table [random_time_series] reference
Creating a slice
Loading [Random long/lat data]
Done loading table!
--------------------------------------------------------------------------------
Creating table reference
Creating a slice
Loading [Country Map data]
Done loading table!
--------------------------------------------------------------------------------
Creating table reference
Creating a slice
Loading [Multiformat time series]
Done loading table!
--------------------------------------------------------------------------------
Creating table [multiformat_time_series] reference
Creating Heatmap charts
Loading [Paris GeoJson]
Creating table paris_iris_mapping reference
Loading [San Francisco population polygons]
Creating table sf_population_polygons reference
Loading [Flights data]
Done loading table!
Loading [BART lines]
Creating table bart_lines reference
Loading [Multi Line]
Creating table [wb_health_population] reference
Creating slices
Creating a World's Health Bank dashboard
Creating some slices
Creating a dashboard
Loading [Misc Charts] dashboard
Creating the dashboard
Loading DECK.gl demo
Loading deck.gl dashboard
Creating Scatterplot slice
Creating Screen Grid slice
Creating Hex slice
Creating Grid slice
Creating Polygon slice
Creating Arc slice
Creating Path slice
Creating a dashboard
Loading [Tabbed dashboard]
Creating a dashboard with nested tabs

这个步骤出现的问题主要是连接不上,因为这个load-examples是从github上下载数据的,所以如果连不上的话,考虑FQ吧。

接下来执行

 python superset init

INFO:root:logging was configured successfully
C:\ProgramData\Anaconda3\envs\superset\lib\site-packages\flask_caching\__init__.py:202: UserWarning: Flask-Caching: CACHE_TYPE is set to null, caching is effectively disabled.
  "Flask-Caching: CACHE_TYPE is set to null, "
INFO:root:Syncing role definition
INFO:root:Syncing Admin perms
INFO:root:Syncing Alpha perms
INFO:root:Syncing Gamma perms
INFO:root:Syncing granter perms
INFO:root:Syncing sql_lab perms
INFO:root:Fetching a set of all perms to lookup which ones are missing
INFO:root:Creating missing datasource permissions.
INFO:root:Creating missing database permissions.
INFO:root:Creating missing metrics permissions
INFO:root:Cleaning faulty perms

最后一步的命令新版本跟我参考的连接里也不一样,新版本命令直接就是run,而老版本是runserver

python .\superset run
INFO:root:logging was configured successfully
C:\ProgramData\Anaconda3\envs\superset\lib\site-packages\flask_caching\__init__.py:202: UserWarning: Flask-Caching: CACHE_TYPE is set to null, caching is effectively disabled.
  "Flask-Caching: CACHE_TYPE is set to null, "
 * Serving Flask app "superset"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
INFO:werkzeug: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
INFO:werkzeug:127.0.0.1 - - [24/Dec/2021 10:48:18] "GET /databaseview/list/ HTTP/1.1" 200 -
INFO:werkzeug:127.0.0.1 - - [24/Dec/2021 10:48:19] "GET /superset/csrf_token/ HTTP/1.1" 200 -
INFO:werkzeug:127.0.0.1 - - [24/Dec/2021 10:48:26] "GET /logout/ HTTP/1.1" 302 -

最后,刚才说到有个路径问题,参考资料给的是

Anaconda3\envs\superset\Lib\site-packages\superset\bin

实际使用的时候会出现

flask fab create-admin
ImportError: cannot import name 'superset' 

的错误,经过排查,应该是切换到

Anaconda3\envs\superset\Scripts 目录,在这个目录中执行就不会报错了。

最后的效果如下:

 

Mysql的问题

在使用MySQL时出现了报错问题

INFO:root:Database.get_sqla_engine(). Masked URL: mysql://abc:XXXXXXXXXX@192.168.1.1
ERROR:root:No module named 'MySQLdb'
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\superset\lib\site-packages\superset\views\core.py", line 1358, in testconn
    engine = database.get_sqla_engine(user_name=username)
  File "C:\ProgramData\Anaconda3\envs\superset\lib\site-packages\superset\utils\core.py", line 131, in __call__
    value = self.func(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\superset\lib\site-packages\superset\models\core.py", line 318, in get_sqla_engine
    return create_engine(sqlalchemy_url, **params)
  File "C:\ProgramData\Anaconda3\envs\superset\lib\site-packages\sqlalchemy\engine\__init__.py", line 525, in create_engine
    return strategy.create(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\superset\lib\site-packages\sqlalchemy\engine\strategies.py", line 87, in create
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "C:\ProgramData\Anaconda3\envs\superset\lib\site-packages\sqlalchemy\dialects\mysql\mysqldb.py", line 118, in dbapi
    return __import__("MySQLdb")
ModuleNotFoundError: No module named 'MySQLdb'

经过搜索排查,是缺少了Mysql的库,参考【使用pip install mysqlclient命令安装mysqlclient失败?_D先生的博客-CSDN博客_mysqlclient】本以为是pymysql,后来发现是mysqlclient库,通过pip install mysqlclient出现了编译错误,所以直接下载打包好的安装,下载路径如下:

​​​​​​Python Extension Packages for Windows - Christoph Gohlke (uci.edu)icon-default.png?t=LBL2https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient注意的是要选择好自己的版本,包括python版本,35\36\37\38\39以及是32还是64位。

在连接好Mysql后出现了中文乱码问题,参考【解决superset中文显示乱码问题_子清的博客-CSDN博客_superset 中文乱码】解决办法是在数据库schema中增加charset

mysql://abc:XXXXXXXXXX@192.168.1.1/testdata?charset=utf8

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值