Hummingbot 第2章:安装指南
本章详细介绍 Hummingbot 的三种安装方式,帮助你根据实际需求选择最适合的方案。
Docker 安装详解
Docker 安装是官方推荐的方式,可以避免系统依赖冲突,一键部署。
安装 Docker
# Ubuntu / Debian
sudo apt-get update
sudo apt-get install docker.io docker-compose
sudo systemctl start docker
sudo systemctl enable docker
# macOS (使用 Homebrew)
brew install --cask docker
# Windows
# 下载 Docker Desktop: https://www.docker.com/products/docker-desktop
拉取并运行 Hummingbot
# 拉取最新稳定版
docker pull hummingbot/hummingbot:latest
# 创建持久化数据目录
mkdir -p ~/hummingbot/{conf,logs,data,scripts}
# 使用 docker-compose 管理(推荐)
cat > docker-compose.yml << 'EOF'
version: "3.9"
services:
hummingbot:
image: hummingbot/hummingbot:latest
container_name: hummingbot
network_mode: host
volumes:
- ~/hummingbot/conf:/home/hummingbot/conf
- ~/hummingbot/logs:/home/hummingbot/logs
- ~/hummingbot/data:/home/hummingbot/data
- ~/hummingbot/scripts:/home/hummingbot/scripts
stdin_open: true
tty: true
restart: unless-stopped
EOF
# 启动容器
docker-compose up -d
# 进入交互终端
docker attach hummingbot
Docker 常用操作
| 命令 | 说明 |
|---|---|
docker start hummingbot | 启动容器 |
docker stop hummingbot | 停止容器 |
docker attach hummingbot | 进入 Hummingbot 终端 |
docker restart hummingbot | 重启容器 |
docker logs hummingbot -f | 查看实时日志 |
docker exec hummingbot hummingbot --version | 查看版本 |
源码编译安装
适合需要修改核心代码或进行二次开发的用户。
环境准备
# 安装系统依赖(Ubuntu)
sudo apt-get update
sudo apt-get install -y build-essential git
# 安装 Miniconda(如果未安装)
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
克隆与编译
# 克隆仓库
git clone https://github.com/hummingbot/hummingbot.git
cd hummingbot
# 创建 Conda 环境
conda create -n hummingbot python=3.10 -y
conda activate hummingbot
# 安装编译依赖
conda install -y -c conda-forge pip cython
# 安装 Python 依赖
pip install -r requirements.txt
# 编译 C 扩展
python setup.py build_ext --inplace
# 安装 hummbingbot
pip install -e .
更新源码
# 拉取最新代码
git pull origin master
# 重新编译
python setup.py build_ext --inplace
Conda 一键安装
适合 Python 开发者,最快速的上手方式:
安装步骤
# 创建环境
conda create -n hummingbot python=3.10 -y
conda activate hummingbot
# 通过 pip 安装(Conda 环境中)
pip install hummingbot
# 启动
hummingbot
注意事项
# 如果遇到 C 扩展编译错误,安装编译工具
conda install -y -c conda-forge cython
# 某些平台可能需要额外依赖
pip install hummingbot --no-binary :all:
安装方式对比
| 特性 | Docker | 源码编译 | Conda/Pip |
|---|---|---|---|
| 安装难度 | 简单 | 中等 | 简单 |
| 启动速度 | 中等 | 快 | 快 |
| 自定义修改 | 不支持 | 完全支持 | 有限支持 |
| 版本切换 | 通过标签 | 通过 Git | 通过 Pip |
| 系统隔离 | 完全隔离 | 无隔离 | 环境隔离 |
| 推荐场景 | 生产部署 | 二次开发 | 快速体验 |
升级与卸载
Docker 版本升级
# 拉取新版本
docker pull hummingbot/hummingbot:latest
# 停止并删除旧容器
docker stop hummingbot
docker rm hummingbot
# 使用相同参数创建新容器
docker run -it \
--name hummingbot \
--network host \
-v ~/hummingbot_data:/home/hummingbot/data \
hummingbot/hummingbot:latest
源码版本升级
cd hummingbot
git pull origin master
pip install -r requirements.txt
python setup.py build_ext --inplace
卸载 Hummingbot
# Docker 版本
docker stop hummingbot && docker rm hummingbot
docker rmi hummingbot/hummingbot:latest
# 源码版本
conda deactivate
conda env remove -n hummingbot
rm -rf ~/hummingbot
故障排除
常见安装问题
| 问题 | 原因 | 解决方案 |
|---|---|---|
| Docker 权限拒绝 | 用户未在 docker 组 | sudo usermod -aG docker $USER 并重新登录 |
| C 扩展编译失败 | 缺少编译工具 | sudo apt-get install build-essential |
| Conda 安装超时 | 网络问题 | 使用国内镜像源:conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ |
| 端口被占用 | 其他服务占用 15871 | 修改 conf_client.yml 中的端口配置 |