Distutils 找不到 Python.h
我有一个带有扩展部分的 distutils 设置脚本,看起来像这样:
from distutils.core import setup, Extension
my_module = Extension('my_module',
sources = ['my_file.c', 'my_other_file.c'])
setup (name = 'my_module',
version = '1.0',
description = 'My module',
ext_modules = [my_module])
在我的 Mac 上运行 setup.py build
工作正常。当我转移到 Debian 机器时,它失败:
error: Python/Python.h: No such file or directory
我安装了 python2.6
和 python2.6-dev
,并且该文件位于 /usr/包括/Python2.6。
它对问题文件执行的命令:
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c my_module .c -o -build/XYZ/my_module.o
所以它传入的是头文件的位置。
Mac 与 Linux 环境之间唯一明显的区别是 gcc-4.2 与 gcc-4.4 以及 Python 2.7 与 Python 2.6
想法?
编辑:
在有问题的 C 文件中:
#include <Python/Python.h>
#include <Python/structmember.h>
I have a distutils setup script with an Extension section, which looks something like this:
from distutils.core import setup, Extension
my_module = Extension('my_module',
sources = ['my_file.c', 'my_other_file.c'])
setup (name = 'my_module',
version = '1.0',
description = 'My module',
ext_modules = [my_module])
Running setup.py build
works fine on my Mac. When I move to a Debian machine, it fails:
error: Python/Python.h: No such file or directory
I have python2.6
and python2.6-dev
installed, and the file is present at /usr/include/Python2.6
.
The command it executes for the problem file:
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c my_module.c -o -build/XYZ/my_module.o
So it is passing in the location of the header file.
The only obvious difference between the Mac vs Linux environment is gcc-4.2 vs gcc-4.4 and Python 2.7 vs Python 2.6
Ideas?
EDIT:
In the C file in question:
#include <Python/Python.h>
#include <Python/structmember.h>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能在您的模块中,您需要
包含“Python.h”
而不是“Python/Python.h”
?或者您可以尝试导出包含路径,然后尝试使用 gcc 或 g++ 再次编译?
May be in your module, you need to
include "Python.h"
instead of"Python/Python.h"
?or you may try exporting include path, and try compiling again with gcc or g++?
就我而言,我缺少 python3-dev,
sudo apt-get install python3-dev
修复了它。In my case, I was missing python3-dev,
sudo apt-get install python3-dev
fixed it.