2011-02-24 46 views
5

我有一个Distutils安装脚本扩展部分,它看起来是这样的:的Distutils找不到Python.h

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]) 

运行setup.py build我的Mac上工作正常。当我移动到Debian系统中,它失败:我python2.6python2.6-dev安装

error: Python/Python.h: No such file or directory 

,并且该文件存在于/usr/include/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 VS Linux环境之间的唯一明显的区别是GCC-4.2 VS GCC-4.4和Python 2.7 VS Python 2.6中

想法?

编辑:

在有问题的C文件:

#include <Python/Python.h> 
#include <Python/structmember.h> 
+0

您可以尝试将这两行更改为“#include”Python.h“'并重新编译? – YOU 2011-02-24 11:42:26

+0

我做了,它看起来像修复它。任何想法为什么它可以在Mac上使用'Python/Python.h'而不是在Linux上? – Joe 2011-02-24 11:44:32

+0

我认为它只是基于安装选项的不同目录结构,linux在/usr/include/python2.6/下有Python.h,但可能在/usr/include/Python/Python.h下有mac,但我没有mac,所以很难说我的假设是否正确。 – YOU 2011-02-24 11:48:37

回答

5

可能是你的模块中,你需要include "Python.h"而不是"Python/Python.h"

或者您可能会尝试导出包含路径,并尝试再次使用gcc或g ++进行编译?

export C_INCLUDE_PATH=/usr/include/python2.6:$C_INCLUDE_PATH 
export CPLUS_INCLUDE_PATH=/usr/include/python2.6:$CPLUS_INCLUDE_PATH 
+0

恰恰相反!原始文件有'Python/Python.h'(见编辑)。我改变了,只是'包括'。看起来像在两个平台上都可以使用。对此有何评论? – Joe 2011-02-24 11:42:29

+0

+1完美无瑕! *你能指点我一种“GCC配置cheatsheet”或类似的东西吗? – 2011-10-01 07:51:35

1

在我的情况下,我错过了python3-dev,sudo apt-get install python3-dev修复了它。