Distutils can't find Python.h

13.1k Views Asked by At

I have a distutils setup script with an Extension section, which looks something like this:

from distutils.core import setup, Extension

my_module = Extension('my_module',
                sources = ['my_file.c', 'my_other_file.c'])

setup (name = 'my_module',
       version = '1.0',
       description = 'My module',
       ext_modules = [my_module])

Running setup.py build works fine on my Mac. When I move to a Debian machine, it fails:

error: Python/Python.h: No such file or directory

I have python2.6 and python2.6-dev installed, and the file is present at /usr/include/Python2.6.

The command it executes for the problem file:

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c my_module.c -o -build/XYZ/my_module.o

So it is passing in the location of the header file.

The only obvious difference between the Mac vs Linux environment is gcc-4.2 vs gcc-4.4 and Python 2.7 vs Python 2.6

Ideas?

EDIT:

In the C file in question:

#include <Python/Python.h>
#include <Python/structmember.h>
2

There are 2 best solutions below

2
On BEST ANSWER

May be in your module, you need to include "Python.h" instead of "Python/Python.h"?

or you may try exporting include path, and try compiling again with gcc or g++?

export C_INCLUDE_PATH=/usr/include/python2.6:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/usr/include/python2.6:$CPLUS_INCLUDE_PATH
0
On

In my case, I was missing python3-dev, sudo apt-get install python3-dev fixed it.