在尝试编译C扩展模块时缺少Python.h [英] Missing Python.h while trying to compile a C extension module
问题描述
我关注如何使用C \ C ++代码扩展Python的本教程。
名为使用GCC为Microsoft Windows构建扩展模块的部分失败,出现以下错误:
致命错误:Python.h:没有这样的文件或目录
名为使用Microsoft Visual C ++构建扩展模块的部分也失败,并出现类似的错误:
致命错误C1083:无法打开include file:'Python.h':没有这样的文件或目录
我该怎么办?
- 您有python dev文件,以便您可以找到Python.h? li>
- 你的Python.h的位置是否指定给你的编译器?与gcc这通常是通过一个-I路径包括。
找出哪些是失败将解决你的问题。 / p>
您链接的文章:
gcc -c hellomodule.c -I / PythonXY / include
gcc -shared hellomodule.o -L / PythonXY / libs -lpythonXY -o hello.dll
python在默认位置c:\pythonXY(其中X是主版本号,Y是次要版本号)(在你的情况下为Python26)如果你把python放在别的地方替换/ PythonXY从哪里安装它。
I'm following this tutorial on how to extend Python with C\C++ code.
The section named "Building the extension module with GCC for Microsoft Windows" fails for me with the following error:
fatal error: Python.h: No such file or directory
The section named "Building the extension module using Microsoft Visual C++" also fails with a similar error:
fatal error C1083: Cannot open include file: 'Python.h': No such file or directory
What should I do to solve this?
- Do you have the python dev files so that you can find Python.h?
- Do you have the location of Python.h specified to your compiler? with gcc this is usually done through a -I path to include.
Figuring out which of those is failing will solve your problem.
from the article you linked:
gcc -c hellomodule.c -I/PythonXY/include
gcc -shared hellomodule.o -L/PythonXY/libs -lpythonXY -o hello.dll
They assumed you installed python in the default location c:\pythonXY(Where X is the major version number and Y is the minor version number).(in your case Python26) If you put python somewhere else replace /PythonXY with where ever you installed it.
这篇关于在尝试编译C扩展模块时缺少Python.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!