Distutils 找不到 Python.h

发布于 2024-10-19 04:13:23 字数 1015 浏览 4 评论 0原文

我有一个带有扩展部分的 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.6python2.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾铮苏瑾 2024-10-26 04:13:23

可能在您的模块中,您需要包含“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

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++?

export C_INCLUDE_PATH=/usr/include/python2.6:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/usr/include/python2.6:$CPLUS_INCLUDE_PATH
淡淡離愁欲言轉身 2024-10-26 04:13:23

就我而言,我缺少 python3-dev,sudo apt-get install python3-dev 修复了它。

In my case, I was missing python3-dev, sudo apt-get install python3-dev fixed it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文