无法构建 boost python 库(致命错误:pyconfig.h:没有这样的文件或目录)

HAO*_*LEE 7 c++ python ubuntu boost boost-python

我正在尝试在我的 ubuntu 上构建 boost python 库。但是,当我执行

./b2 --with-python
Run Code Online (Sandbox Code Playgroud)

它总是返回与我相关的错误

./boost/python/detail/wrap_python.hpp:57:11: fatal error: pyconfig.h: No such file or directory
 # include <pyconfig.h>
           ^~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

我尝试在线查找,例如https://github.com/boostorg/build/issues/289

按照他们的建议,我检查了我的“project-config.jam”,我发现

# Python configuration
import python ;
if ! [ python.configured ]
{
    using python : 3.7 : /home/lowlimb/anaconda3 :/home/lowlimb/anaconda3/include/python3.7m;
}

Run Code Online (Sandbox Code Playgroud)

这是正确的,因此我真的不知道如何解决这个问题。有人可以给我一些建议吗?

小智 5

pyconfig.h安装有sudo apt install python-dev

要使用特定的 python 版本构建,你可以这样做

./bootstrap.sh --with-python=<path to python>
Run Code Online (Sandbox Code Playgroud)

例如

./bootstrap.sh --with-python=python3
Run Code Online (Sandbox Code Playgroud)

使用系统的 python3 或

./bootstrap.sh --with-python=$VIRTUAL_ENV/bin/python
Run Code Online (Sandbox Code Playgroud)

从虚拟环境中使用 python。


Mar*_*ius 5

除了按照其他答案的建议安装 python 开发库之外,您还可以直接指定 python 路径:

CPLUS_INCLUDE_PATH=/usr/include/python3.7 make
Run Code Online (Sandbox Code Playgroud)

或者在你的情况下类似:

CPLUS_INCLUDE_PATH=/home/lowlimb/anaconda3/include/python3.7 ./b2
Run Code Online (Sandbox Code Playgroud)

当我使用 Boost Python 编译项目时,这对我有用,但我遇到了同样的错误。


rus*_*tyx 1

为了构建 Boost-Python 或者更一般地,从 C/C++ 使用 Python,您需要Python 开发文件

$ sudo apt install python3.7-dev
Run Code Online (Sandbox Code Playgroud)