封面

建议优先了解以下几个关键词:Python 多版本、虚拟环境、uv、pip…

为什么选择树莓派 5?

树莓派 5 为 AI 应用部署提供了理想平台:

• 更强的性能:BCM2712 四核 Cortex-A76 CPU

• PCIe 接口:支持 NVMe SSD

• 双 4K 显示输出

• 低功耗:约 5W

• 开源生态,便宜

系统要求与准备

硬件需求

文章配图

组件

最低配置

推荐配置

CPU

Raspberry Pi 4

Raspberry Pi 5

RAM

4GB

8GB

Storage

32GB microSD

128GB+ NVMe SSD

Power

5V/3A USB-C

5V/5A PD

软件环境准备

更新系统并安装基础工具:
sudo apt update && sudo apt upgrade -y
sudo apt install -y git curl wget vim build-essential

依赖项安装

Python 环境配置

使用 Pyenv 安装 Python 3.11:
curl https://pyenv.run | bash
export PYENV_ROOT=”$HOME/.pyenv”
pyenv install 3.11.9
pyenv global 3.11.9

核心依赖安装

Python 虚拟环境

mkdir -p ~/hermes-agent && cd ~/hermes-agent
python -m venv venv && source venv/bin/activate

系统级依赖

sudo apt install -y libffi-dev libssl-dev libpq-dev
libxml2-dev libxslt1-dev zlib1g-dev
pkg-config cmake gcc g++

Python 包依赖

pip install hermes-agent fastapi uvicorn pydantic torch transformers python-dotenv

Hermes Agent 部署步骤

从 GitHub 克隆源码

cd ~/hermes-agent
git clone https://github.com/hermes-ai/agent.git .
git checkout v1.0.0
pip install -e .

配置环境变量

创建 .env 文件:
HERMES_API_KEY=your_api_key_here
OPENAI_API_KEY=your_openai_key
HOST=0.0.0.0
PORT=8000

启动服务

开发模式

uvicorn app.main:app –reload –host 0.0.0.0 –port 8000

生产模式

sudo nano /etc/systemd/hermes-agent.service

配置 systemd 服务…

sudo systemctl enable hermes-agent
sudo systemctl start hermes-agent

性能优化技巧

CPU 频率调整

echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

NVMe SSD 加速

sudo mkfs.ext4 /dev/nvme0n1p1
sudo mount /dev/nvme0n1p1 /mnt/nvme

Docker 部署

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
docker run -d –name hermes -p 8000:8000 -e HERMES_API_KEY=your_key hermes-agent

常见问题解决

Q1: Python 版本冲突

解决方案:使用 pyenv 安装新版本
pyenv install 3.11.9 && pyenv global 3.11.9

Q2: pip 安装失败

解决方案:升级 certifi
pip install –upgrade certifi
sudo apt install -y ca-certificates

Q3: 内存不足

解决方案:增加交换空间,减少 workers
sudo dphys-swapfile swapoff

编辑 /etc/dphys-swapfile 设置 CONF_SWAPSIZE=2048

sudo dphys-swapfile setup && sudo dphys-swapfile swapon

参考资料

• Hermes Agent GitHub

• Raspberry Pi 5 官方规格

• Python Installation Guide

• Raspberry Pi Forums

• Hugging Face Edge Models

• FastAPI Documentation

• Uvicorn Server Guide

公众号原文