Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 508
Jonathan Livni Avatar asked Nov 04 '10 13:11

Jonathan Livni


2 Answers

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

like image 80
Karim Avatar answered Nov 20 '22 15:11

Karim


  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.

like image 34
stonemetal Avatar answered Nov 20 '22 15:11

stonemetal