1.下载python 3.11版本
选择3.11版本的原因是后面安装Anaconda时需要指定3.11版本,才不会在下载地址
2.下载Anaconda 免费版本
下载后安装直接点击安装,如果安装时在 setting up the base过程卡住,那么是下载的python版本没有对应Anaconda的安装的Python版本所以会卡住
直接把运行程序加载到环境变量中,我的安装地址是:D:\anacon
因此:在环境变量中Path新增 三个变量,
D:\anacon,
D:\anacon\Scripts,
D:\anacon\Library\bin
新开一个终端 输入 conda --version 输出版本号则说明成功。
3.下载Pycharm
Pycharm 比较好用,且配合Anaconda创建虚拟环境会更方便 下载地址
4.克隆superset项目
git clone https://github.com/apache/superset.git
5.创建虚拟环境
我这里以Python3.8版本的为例子
# 创建Python 3.8版本的环境
conda create --name superset_env python=3.8
# 激活虚拟环境
conda activate superset_env
6.安装Superset 依赖
首先切换到项目目录里,然后在安装依赖
cd superset
conda install -c conda-forge python=3.8 superset
7.初始化数据库
# 初始化数据库
superset db upgrade
#设置FLASK_APP
set FLASK_APP=superset
上述步骤可能会出现一个警告,提示是默认的 SECRET_KEY被删除,需要使用
openssl rand -base64 42 生成一个新的
然后在Superset目录下新建一个 superset_config.py 的文件,我们复制这个值SECRET_KEY =“”添加到 文件中 。
# Superset specific config
ROW_LIMIT = 5000
# Flask App Builder configuration
# Your App secret key will be used for securely signing the session cookie
# and encrypting sensitive information on the database
# Make sure you are changing this key for your deployment with a strong key.
# Alternatively you can set it with `SUPERSET_SECRET_KEY` environment variable.
# You MUST set this for production environments or the server will not refuse
# to start and you will see an error in the logs accordingly.
SECRET_KEY = 'vd0ddNuXm4jCJHYbuzcNrIwyevhseK/5SInS0gZYhkkOOo0crgVVnufk'
# The SQLAlchemy connection string to your database backend
# This connection defines the path to the database that stores your
# superset metadata (slices, connections, tables, dashboards, ...).
# Note that the connection information to connect to the datasources
# you want to explore are managed directly in the web UI
# The check_same_thread=false property ensures the sqlite client does not attempt
# to enforce single-threaded access, which may be problematic in some edge cases
# SQLALCHEMY_DATABASE_URI = 'mysql://root:root@localhost/superest'
# SQLALCHEMY_DATABASE_URI = 'sqlite://~/.superset/superset.db'
BABEL_DEFAULT_LOCALE = "zh"
# Flask-WTF flag for CSRF
WTF_CSRF_ENABLED = False
# Add endpoints that need to be exempt from CSRF protection
WTF_CSRF_EXEMPT_LIST = []
# A CSRF token that expires in 1 year
WTF_CSRF_TIME_LIMIT = 60 * 60 * 24 * 365
# Set this API key to enable Mapbox visualizations
MAPBOX_API_KEY = ''
为了能够在每次启动项目时都能够读取到这个配置,所以要把这个文件添加到系统的换件变量里
变量名为:SUPERSET_CONFIG_PATH
值为:superset_config.py文件的地址 例如
添加环境变量后需要重启Pycharm配置才能生效。
8.创建账号密码
firstname、lastname和email 可直接回车跳过,输入两次密码
superset fab create-admin
9.Superset初始化和加载实例
#项目初始化
superset init
#加载样例数据
superset load_examples
10.运行项目
superset run -h 0.0.0.0 -p 8088 --with-threads --reload --debugger
11.常见错误
错误1:ImportError: cannot import name 'url_quote' from 'werkzeug.urls'
该问题是由于werkzeug版本过高导致的,可以执行以下命令
# 卸载最新版本的包
pip uninstall Werkzeug
# 安装2.0.1版本的包 原因是Superset版本不兼容 3.0版本的Werkzeug
pip install Werkzeug==2.0.1