Missing Python.h while trying to compile a C extension module(尝试编译 C 扩展模块时缺少 Python.h)
问题描述
我正在关注关于如何使用 CC++ 代码扩展 Python 的本教程.
I'm following this tutorial on how to extend Python with CC++ code.
名为Building the extension module with GCC for Microsoft Windows"的部分对我来说失败并出现以下错误:
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
名为使用 Microsoft Visual C++ 构建扩展模块"的部分也失败并出现类似错误:
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?
推荐答案
- 您是否有 Python 开发文件以便您可以找到 Python.h?
- 是否为编译器指定了 Python.h 的位置?对于 gcc,这通常是通过包含的 -I 路径完成的.
找出哪些失败将解决您的问题.
Figuring out which of those is failing will solve your problem.
来自您链接的文章:
gcc -c hellomodule.c -I/PythonXY/include
gcc -c hellomodule.c -I/PythonXY/include
gcc -shared hellomodule.o -L/PythonXY/libs -lpythonXY -o hello.dll
gcc -shared hellomodule.o -L/PythonXY/libs -lpythonXY -o hello.dll
他们假设您在默认位置 c:pythonXY 安装了 python(其中 X 是主要版本号,Y 是次要版本号).(在您的情况下为 Python26)如果您将 python 放在其他地方,请将/PythonXY 替换为 where你安装过它.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:尝试编译 C 扩展模块时缺少 Python.h
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
