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

5

我正在尝试在我的Ubuntu上构建boost python库。然而,当我执行以下命令时:

./b2 --with-python

我经常遇到与此相关的错误:

./boost/python/detail/wrap_python.hpp:57:11: fatal error: pyconfig.h: No such file or directory
 # include <pyconfig.h>
           ^~~~~~~~~~~~

我尝试在网上查找,例如,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;
}

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

3个回答

5
除了安装其他答案建议的Python开发库之外,您还可以直接指定Python路径:
CPLUS_INCLUDE_PATH=/usr/include/python3.7 make

或者在您的情况下,类似于以下内容:

CPLUS_INCLUDE_PATH=/home/lowlimb/anaconda3/include/python3.7 ./b2

当我编译使用Boost Python的项目时,我遇到了同样的错误,以下方法对我有效。


5

pyconfig.h可以通过 sudo apt install python-dev 安装。

要使用特定的Python版本进行构建,可以执行以下操作:

./bootstrap.sh --with-python=<path to python>

e.g.

./bootstrap.sh --with-python=python3

使用您系统的Python3或

./bootstrap.sh --with-python=$VIRTUAL_ENV/bin/python

使用你的虚拟环境中的Python。


1
为了构建Boost-Python或更一般地从C/C++中使用Python,您需要Python开发文件
$ sudo apt install python3.7-dev

我需要对project-config.jam做些什么吗?它仍在使用anaconda的python。 - HAO LEE

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接