微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ubuntu – 链接boost.python – 致命错误:无法findpyconfig

有一些问题,现在我读了以下内容

你好世界python扩展在c + +使用boost?

我已经尝试安装提升到我的桌面上,并作为postbuild议的链接我有以下代码

#include <boost/python.hpp> #include <Python.h> using namespace boost::python;

现在我尝试了以下链接

为什么使用std :: thread :: hardware_concurrency()和boost :: thread :: hardware_concurrency()有区别?

交叉编译PowerPC架构的Boost库

带有汇的boost_log示例无法编译

CMakeLists无法find新安装的HDF5?

Boost ::进程间共享内存总线错误

g++ testing.cpp -I /usr/include/python2.7/pyconfig.h -L /usr/include/python2.7/Python.h -lpython2.7

我也尝试了以下内容

g++ testing.cpp -I /home/username/python/include/ -L /usr/include/python2.7/Python.h -lpython2.7

我不断收到以下错误

/usr/include/boost/python/detail/wrap_python.hpp:50:23: Fatal error: pyconfig.h: No such file or directory # include <pyconfig.h>

我不知道我哪里错了。 我有boost.python安装,只有一个问题链接

互斥体在boost regex构造函数中声明

Linux的初学者,在哪里把增强图书馆?

创buildLinux make / build文件

这是一个错误在boost :: filesystem? 为什么boost :: filesystem :: path :: string()在Windows和Linux上没有相同的签名?

使用boost文件系统parsing符号链接

我只是有同样的错误,问题是g ++无法找到pyconfig.h(令人震惊,我知道)。 对我来说,这个文件位于/usr/include/python2.7/pyconfig.h所以附加-I /usr/include/python2.7/应该修复它,或者你可以添加目录到你的路径:

export CPLUS_INCLUDE_PATH="$CPLUS_INCLUDE_PATH:/usr/include/python2.7/"

您也可以将其添加到您的.bashrc中,并且每当您启动您的shell时,它都会被添加(您将不得不重新打开终端以实现更改)。

你可以使用find /usr/include -name pyconfig.h找到你自己的python包含路径,在我的情况下会返回:

/usr/include/python2.7/pyconfig.h /usr/include/i386-linux-gnu/python2.7/pyconfig.h

如果您有一个.c文件( hello.c ),并且想要构建一个libhello.so库,请尝试:

find /usr/include -name pyconfig.h

[OUT]:

/usr/include/python2.7/pyconfig.h /usr/include/x86_64-linux-gnu/python2.7/pyconfig.h

然后使用输出并做:

gcc -shared -o libhello.so -fPIC hello.c -I /usr/include/python2.7/

如果你从cython的.pyx转换到.so,试试这个python模块,它会自动生成.so文件给.pyx文件

def pythonizing_cython(pyxfile): import os # Creates ssetup_pyx.py file. setup_py = "n".join(["from distutils.core import setup","from Cython.Build import cythonize","setup(ext_modules = cythonize('"+ pyxfile+".pyx'))"]) with open('setup_pyx.py','w') as fout: fout.write(setup_py) # Compiles the .c file from .pyx file. os.system('python setup_pyx.py build_ext --inplace') # Finds the pyconfig.h file. pyconfig = os.popen('find /usr/include -name pyconfig.h' ).readline().rpartition('/')[0] # Builds the .so file. cmd = " ".join(["gcc -shared -o",pyxfile+".so","-fPIC",pyxfile+".c","-I",pyconfig]) os.system(cmd) # Removing temporary .c and setup_pyx.py files. os.remove('setup_pyx.py') os.remove(pyxfile+'.c')

在为centos7建设时,我也有类似的经历。 我无法在我的系统上找到pyconfig.h,只有pyconfig-64.h。

搜索后,我发现你需要安装python-devel来获取pyconfig.h

这个症状有两个可能的原因:1.你没有安装python-dev。 2.你安装了python-dev,你的包含路径配置不正确,上面的贴子提供了一个解决方案。 在我的情况下,我正在安装boost,它正在寻找我的ubuntu中缺少的pyconfig.h头文件

解决方案是

apt-get install python-dev

在其他的linux版本中,你必须弄清楚如何安装python头文件

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐