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 中的端口配置