Missing Python.h while trying to compile a C extension module

怎甘沉沦 提交于 2019-11-27 03:28:58

问题


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:


  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.




回答2:


For Linux, Ubuntu users to resolve the issue of missing Python.h while compiling, simply run the following command in your terminal to install the development package of python:

In Terminal: sudo apt-get install python-dev

Good luck



来源:https://stackoverflow.com/questions/4097339/missing-python-h-while-trying-to-compile-a-c-extension-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!