# 安装Superset到Mac电脑

### 安装时间

大约需要1-2小时。

### 安装Superset - 安装进Python虚拟机

[Superset](https://superset.incubator.apache.org/installation.html)提供3种安装方式：1）安装进Docker 2）直接安装进操作系统 3）安装进Python虚拟机。第1种方式来自社区志愿者，没有项目核心人员在维护这种发式，安装过程中可能会有些问题，本人就通过docker死活装不上；第2种方式不推荐，因为Superset会依赖很多包，直接装进操作系统可能会和其他应用冲突；所以推荐使用Python虚拟机进行安装。以下是安装步骤。

#### 安装Python3.6

因为Superset需要运行在Python3.6及以上版本里，所以需要首先运行：

```python
python3 --version
```

确认你是否有Python3.6及以上版本，如果没有可以去[Python](https://www.python.org/downloads/)官网下载并安装最新版。

#### 安装Python虚拟机visualenv

```python
pip install virtualenv
```

创建和激活virtualenv：

```python
# virtualenv is shipped in Python 3.6+ as venv instead of pyvenv.
# See https://docs.python.org/3.6/library/venv.html
python3 -m venv venv
. venv/bin/activate
```

一旦激活后你的所有操作都在Python虚拟机里面，要退出的话输入`deactivate`。

#### Python的配置工具和pip

```python
pip install --upgrade setuptools pip
```

#### Superset的安装和初始化

```python
# Install superset
pip install superset

# Create an admin user (you will be prompted to set a username, first and last name before setting a password)
fabmanager create-admin --app superset

# Initialize the database
superset db upgrade

# Load some data to play with
superset load_examples

# Create default roles and permissions
superset init

# To start a development web server on port 8088, use -p to bind to another port
superset runserver -d
```

打开[http://localhost:8088](http://localhost:8088/)就可以查看你的Superset。

**问题**

在Superset的安装和初始化中可能会遇到的2个问题。

问题1：

```
Was unable to import superset Error: cannot import name '_maybe_box_datetimelike' from 'pandas.core.common' (/usr/bin/venv/lib/python3.7/site-packages/pandas/core/common.py)
```

解决方法：跟pandas版本有关，卸载掉重装低版本，参考来源：<https://github.com/apache/incubator-superset/issues/6770。>

```python
pip uninstall pandas
pip list | grep pandas
pip install pandas==0.23.4
```

问题2：

```
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.
```

解决方法：安装sqlalchemy 1.2.18，参考来源：<https://github.com/apache/incubator-superset/issues/6977。>

```python
pip install sqlalchemy==1.2.18
```

### 运行

当你不小心关闭终端，或中断了进程 ，你会发现[http://localhost:8088](http://localhost:8088/)会打不开。这时候就需要重新激活虚拟机，并运行superset就可以了。

```python
. venv/bin/activate
superset runserver -d
```

### 参考

1. [Apache Superset Installation & Configuration](https://superset.incubator.apache.org/installation.html)
2. [superset可视化clickhouse安装教程](https://wchch.github.io/2019/03/25/superset可视化clickhouse安装教程/)
3. [可能是目前颜值最高的开源BI工具-Superset](http://jackpgao.github.io/2018/05/30/Superset-Introduce/)
4. [Superset 分析示例数据](https://greenlightt.github.io/2017/11/22/superset-demo-example/)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mayalin.gitbook.io/product101/an-zhuang-superset-dao-mac-dian-nao.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
