【发布时间】:2011-02-24 11:26:45
【问题描述】:
我有一个带有扩展部分的 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])
运行 setup.py build 在我的 Mac 上运行良好。当我移动到 Debian 机器时,它失败了:
error: Python/Python.h: No such file or directory
我安装了python2.6 和python2.6-dev,文件位于/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 与 Linux 环境之间唯一明显的区别是 gcc-4.2 与 gcc-4.4 以及 Python 2.7 与 Python 2.6
想法?
编辑:
在有问题的 C 文件中:
#include <Python/Python.h>
#include <Python/structmember.h>
【问题讨论】:
-
你能不能试着把这两行改成
#include "Python.h"然后重新编译? -
我做到了,看起来可以解决问题。知道为什么它可以在 mac 上与“Python/Python.h”一起使用,但在 linux 上却不行吗?
-
我认为它只是基于安装选项的目录结构不同,linux在/usr/include/python2.6/下有Python.h,但mac可能在/usr/include/Python/Python.h下,但我没有mac,所以很难说我的假设是否正确。
-
啊,是的,有不同的方法可以获取适用于 Mac 的 Python!我认为它使用的是“/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h”(/usr/include 中也有版本)。
标签: python gcc distutils python-c-extension