c python.h_在尝试编译C扩展模块时缺少Python.h

在尝试使用GCC或Microsoft Visual C++编译Python扩展模块时,遇到了找不到'Python.h'头文件的错误。这通常是因为缺少Python开发文件或者没有正确指定编译器的包含路径。解决方法包括确保安装了Python开发文件,并将Python的include目录添加到编译器的-I选项中。如果Python不在默认路径,需要替换编译命令中的Python路径为实际安装位置。
摘要由CSDN通过智能技术生成

1586010002-jmsa.png

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值