在尝试编译C扩展模块时缺少Python.h [英] Missing Python.h while trying to compile a C extension module

查看:2575
本文介绍了在尝试编译C扩展模块时缺少Python.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关注如何使用C \ C ++代码扩展Python的本教程



名为使用GCC为Microsoft Windows构建扩展模块的部分失败,出现以下错误:

 致命错误:Python.h:没有这样的文件或目录

名为使用Microsoft Visual C ++构建扩展模块的部分也失败,并出现类似的错误:

 致命错误C1083:无法打开include file:'Python.h':没有这样的文件或目录

我该怎么办?

解决方案


  1. 您有python dev文件,以便您可以找到Python.h? li>
  2. 你的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?

解决方案

  1. Do you have the python dev files so that you can find Python.h?
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆