如何使用本地 Python 版本构建 Boost::Python(不使用 sudo)

我已经按照如何在不使用 sudo 的情况下构建和安装 Python 3.13中的说明构建并安装了 Python。

尝试仅使用 --with-python 构建 boost::python 时,它找不到 Python 头文件:

boost_python_config.txt
warning: No python installation configured and autoconfiguration
note: failed.  See http://www.boost.org/libs/python/doc/building.html
note: for configuration instructions or pass --without-python to
note: suppress this message and silently skip all Boost.Python targets

为了解决这个问题,创建 tools/build/src/user-config.jam,内容如下:

user-config.jam
using python
    : 3.13
    : ~/usr/bin/python3.13
    : ~/usr/include/python3.13
    : ~/usr/lib
    ;

然后,使用以下命令构建 boost::python:

build_boost_python.sh
./b2 install --with-python --prefix=$HOME/usr include=~/usr/include/python3.13

记住将 3.13 替换为你安装的实际版本,将 ~/usr 替换为你使用的实际安装前缀。


Check out similar posts by category: Boost, Python, Linux