CentOS 8 安装 Apache Burr 指南
CentOS 8 从零安装 Apache Burr 0.42.0 实测指南:修复 vault 源、启用 python39、虚拟环境 pip 安装、demo 验证及编译 Python 3.11 解决 CLI 兼容性,全程真实回显。
CentOS 8 安装 Apache Burr 指南
目标:在 CentOS 8 服务器上从零安装 Apache Burr 0.42.0(Apache Incubating 项目,Python 轻量工作流/状态机框架),覆盖 yum vault 归档源修复、python39 应用流启用、Python 虚拟环境创建、pip 安装、状态机 demo 运行验证,以及为 CLI 工具编译升级 Python 3.11 的完整流程。以下命令与回显均在真实环境逐步实测。
一、环境信息
Apache Burr 由 Apache Software Foundation 孵化,定位为"用简单 Python 积木构建会做决策的应用"(聊天机器人、智能体、仿真等)的轻量状态机框架。本文实测服务器环境如下:
- 操作系统:CentOS Linux release 8.4.2105 (Core)(x86_64)
- Python 版本路径:dnf 模块 python39(Python 3.9.6,pip 20.2.4)→ 源码编译 Python 3.11.9(安装于 /usr/local/python311)
- 软件版本:burr 0.42.0(PyPI 迁移壳包,实际安装主体为 apache-burr 0.42.0)
- 网络环境:CentOS 8 官方源已停止维护,镜像切换至清华大学 TUNA vault 归档源;PyPI 拉包使用内网代理 http://192.168.1.62:7897 加速
环境基线实测回显:
cat /etc/os-release | head -3
NAME="CentOS Linux"
VERSION="8"
ID="centos"
python3 --version
Python 3.9.6
验证结果:操作系统与 Python 基线版本确认无误。
二、yum vault 归档源修复
CentOS 8 停止维护后,官方 mirrorlist.centos.org 域名已不可解析,dnf 无法拉取仓库元数据。需将三个仓库文件中的 mirrorlist 注释掉,并将 baseurl 指向清华大学 TUNA 的 centos-vault 归档镜像(8.5.2111 分支)。
sed -i 's|^mirrorlist=|#mirrorlist=|; s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/8.5.2111|' /etc/yum.repos.d/CentOS-Linux-BaseOS.repo /etc/yum.repos.d/CentOS-Linux-AppStream.repo /etc/yum.repos.d/CentOS-Linux-Extras.repo
dnf clean all
dnf makecache
修改后 BaseOS 仓库文件关键配置实测回显:
[baseos]
name=CentOS Linux $releasever - BaseOS
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/8.5.2111/BaseOS/$basearch/os/
gpgcheck=1
仓库列表实测回显:
repo id repo name
appstream CentOS Linux 8 - AppStream
baseos CentOS Linux 8 - BaseOS
extras CentOS Linux 8 - Extras
验证结果:三个仓库全部列出且无报错,vault 归档源修复完成。
三、启用 python39 应用流
CentOS 8 AppStream 应用流(module)最高提供 Python 3.9,先查询模块状态再安装。
dnf module list python39
dnf module install -y python39
模块列表实测回显(关键行):
Name Stream Profiles Summary
python39 3.9 [d][e] build, common [d] [i] Python programming language, version 3.9
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
版本验证回显:
python3 --version
Python 3.9.6
pip3 --version
pip 20.2.4 from /usr/lib/python3.9/site-packages/pip (python 3.9)
验证结果:python3 命令已指向 3.9.6,pip 随模块一并就绪。
四、创建虚拟环境并安装 Apache Burr
为隔离系统 Python 环境,使用 venv 创建独立虚拟环境;PyPI 直连下载缓慢,统一走内网代理。
python3 -m venv /opt/burr-demo/.venv
. /opt/burr-demo/.venv/bin/activate
pip install --proxy http://192.168.1.62:7897 "burr[start]"
安装过程实测回显(关键行):
Collecting burr
Downloading burr-0.42.0-py3-none-any.whl (2.3 kB)
Collecting apache-burr==0.42.0
Downloading apache_burr-0.42.0-py3-none-any.whl (4.7 MB)
Installing collected packages: apache-burr, burr
Successfully installed apache-burr-0.42.0 burr-0.42.0
补充说明:burr 是迁移壳包,仅 2.3 kB,指向实际主体 apache-burr 0.42.0(约 4.7 MB);[start] 扩展提供 CLI 与 Web UI 所需的 click、FastAPI、Uvicorn 等依赖,未安装该扩展时 CLI 会报 Missing plugin start! 错误。
版本验证回显:
pip show apache-burr | grep -E "Name|Version"
Name: apache-burr
Version: 0.42.0
验证结果:apache-burr 0.42.0 安装成功,命令入口 burr 就绪。
五、状态机 demo 运行验证
编写一个"计数器累加到 3 后转入汇总"的两动作状态机应用,验证 burr 库在 Python 3.9 环境下可正常运行。程序示例 app.py:
from burr.core import action, State, ApplicationBuilder, expr, default
@action(reads=[], writes=["count"])
def counter(state: State) -> State:
return state.update(count=state["count"] + 1)
@action(reads=["count"], writes=["result"])
def summarize(state: State) -> State:
return state.update(result=f"count reached {state['count']}")
app = (
ApplicationBuilder()
.with_actions(counter=counter, summarize=summarize)
.with_transitions(
("counter", "counter", expr("count < 3")),
("counter", "summarize", default),
)
.with_state(count=0, result="")
.with_entrypoint("counter")
.with_tracker(project="burr-quickstart")
.build()
)
last_action, result, state = app.run(halt_after=["summarize"])
print("stopped after action:", last_action.name)
print("result:", result)
print("final state:", state)
运行命令:
python3 app.py
实测回显:
stopped after action: summarize
result: {}
final state: {'count': 3, 'result': 'count reached 3', '__SEQUENCE_ID': 3, '__PRIOR_STEP': 'summarize'}
验证结果:count 从 0 累加至 3,满足计数条件后转入 summarize 并输出汇总,状态机执行链路正确;with_tracker 同时将执行轨迹落盘至 ~/.burr/burr-quickstart/ 目录。
六、CLI 崩溃分析与 Python 3.11 编译升级
burr 库本体在 Python 3.9 下运行正常,但 CLI 工具因源码使用 PEP 604 联合类型语法(dict | None),在 Python 3.10 以下会于启动阶段崩溃,因此需要编译升级 Python 3.11。
6.1 复现 CLI 崩溃
命令:
burr --help
实测回显:
Traceback (most recent call last):
File "/opt/burr-demo/.venv/bin/burr", line 3, in <module>
from burr.cli.__main__ import cli_run_server
File "/opt/burr-demo/.venv/lib64/python3.9/site-packages/burr/cli/__main__.py", line 53, in <module>
def _command(command: str, capture_output: bool, addl_env: dict | None = None) -> str:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
原因分析:PEP 604 的 dict | None 语法在函数默认参数处于运行时求值,Python 3.9 不识别该写法;而 apache-burr 包元数据声明 Requires-Python>=3.9,库代码本身规避了此语法,因此 import burr 与应用运行均不受影响。
6.2 安装编译依赖
dnf install -y gcc make zlib-devel bzip2-devel openssl-devel libffi-devel readline-devel sqlite-devel xz-devel wget tar
依赖校验实测回显:
rpm -q gcc make zlib-devel bzip2-devel openssl-devel libffi-devel readline-devel sqlite-devel xz-devel
zlib-devel-1.2.11-17.el8.x86_64
bzip2-devel-1.0.6-26.el8.x86_64
openssl-devel-1.1.1k-5.el8_5.x86_64
libffi-devel-3.1-22.el8.x86_64
readline-devel-7.0-10.el8.x86_64
sqlite-devel-3.26.0-15.el8.x86_64
xz-devel-5.2.4-3.el8.x86_64
验证结果:编译所需依赖全部就绪。
6.3 下载并编译 Python 3.11.9
python.org 直连下载不完整,必须走代理;完整源码包实测 26,521,757 字节(约 25.3 MB)。
wget -x http://192.168.1.62:7897 https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tgz
tar xzf Python-3.11.9.tgz
cd Python-3.11.9
./configure --prefix=/usr/local/python311 --with-ssl
make -j2
make install
编译安装完成后版本验证回显:
/usr/local/python311/bin/python3.11 --version
Python 3.11.9
验证结果:Python 3.11.9 编译安装成功,二进制位于 /usr/local/python311/bin/python3.11。
6.4 基于 Python 3.11 重建虚拟环境并验证 CLI
/usr/local/python311/bin/python3.11 -m venv /opt/burr-demo/py311-venv
. /opt/burr-demo/py311-venv/bin/activate
pip install --proxy http://192.168.1.62:7897 "burr[start]"
安装过程实测回显(结尾关键行,依赖清单约 80 项,含 click、httpx、pydantic、numpy、pandas 等):
Successfully installed apache-burr-0.42.0 burr-0.42.0 fastapi-0.143.0 uvicorn-0.54.0 openai-3.29.0
CLI 验证回显:
burr --help
Usage: burr [OPTIONS]
Options:
--port INTEGER Port to run the server on
--dev-mode Run the server in development mode
--no-open Run the server without opening it
--no-copy-demo_data Don't copy demo data over.
--host TEXT Host to run the server on -- use 0.0.0.0 if you want
to expose it to the network
--backend [local|s3] Backend to use for the server.
--help Show this message and exit.
demo 复验回显:
python3 app.py
stopped after action: summarize
result: {}
final state: {'count': 3, 'result': 'count reached 3', '__SEQUENCE_ID': 3, '__PRIOR_STEP': 'summarize'}
验证结果:Python 3.11 环境下 burr CLI 与状态机 demo 均正常运行,安装流程闭环完成。
七、参考链接
- Apache Burr 官方文档:https://burr.dagworks.io/
- Apache Burr GitHub 仓库:https://github.com/apache/burr
- PyPI burr 包页面:https://pypi.org/project/burr/
- PyPI apache-burr 包页面:https://pypi.org/project/apache-burr/
- Apache Incubator Burr 项目页:https://incubator.apache.org/projects/burr.html
- Python 3.11 源码下载页:https://www.python.org/ftp/python/3.11.9/
- 清华大学 TUNA CentOS Vault 镜像:https://mirrors.tuna.tsinghua.edu.cn/centos-vault/