You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS Monterey下Python3.12编译libtorrent失败求助

解决macOS Monterey下Python3.12安装libtorrent时找不到-lboost_python312的问题

问题根源

brew默认安装的Boost没有针对Python3.12编译对应的boost_python312库,导致链接器无法找到该依赖。

解决方案

方案一:手动编译Boost的Python绑定(推荐)

  • 卸载brew安装的Boost(避免版本冲突):
    brew uninstall boost
    
  • 下载与libtorrent兼容的Boost源码(以1.82.0版本为例),解压并进入目录:
    wget https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/boost_1_82_0.tar.gz
    tar -xzf boost_1_82_0.tar.gz
    cd boost_1_82_0
    
  • 执行bootstrap脚本,指定Python3.12路径(根据实际路径调整):
    ./bootstrap.sh --with-python=/usr/local/bin/python3.12
    
  • 编译并安装Boost,仅编译Python组件以节省时间:
    ./b2 install --with-python
    
  • 回到libtorrent目录,清理之前的编译缓存后重新编译:
    cd ../libtorrent
    rm -rf build dist *.egg-info
    python setup.py bdist_wheel
    

方案二:修改libtorrent的setup.py适配Boost库命名

brew安装的Boost可能将Python库命名为boost_python3或boost_python312-mt,而非boost_python312:

  • 打开libtorrent目录下的setup.py文件
  • 找到查找Boost Python库的代码段(搜索boost_python关键词定位),将boost_python312替换为系统中实际存在的库名(可通过ls /usr/local/lib/libboost_python*查看)
  • 清理编译缓存后重新运行编译命令:
    rm -rf build dist *.egg-info
    python setup.py bdist_wheel
    

方案三:尝试安装预编译轮子

如果不需要最新版本的libtorrent,可直接通过pip尝试安装预编译好的轮子:

pip install libtorrent

注意事项

  • 确保当前使用的Python3.12是你预期的版本,可通过which python3和python3 --version确认
  • 编译Boost时指定的Python路径必须与编译libtorrent时使用的Python路径一致
  • 若之前有多次编译失败,务必清理编译缓存后再重新尝试

内容的提问来源于stack exchange,提问作者a82fd72deb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 15:07:11