Distutils can't find Python.h
Asked Answered
O

2

6

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>
Overdrive answered 24/2, 2011 at 11:26 Comment(4)
Could you try to change that two lines to just #include "Python.h" and compile again?Scythe
I did, and it looks like that fixes it. Any idea why it would work with 'Python/Python.h' on the mac but not on linux?Overdrive
I think it simply the directory structure different based on install option, linux have Python.h under /usr/include/python2.6/ but mac probably under /usr/include/Python/Python.h, but I don't have mac, so its hard to say my assuming is correct or not.Scythe
Ah yes, there are different ways to get Python for the Mac! The one I think it's using is "/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h" (there are versions in /usr/include too).Overdrive
S
6

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
Scythe answered 24/2, 2011 at 11:34 Comment(2)
Quite the opposite! The original file had Python/Python.h (see edit). I changed that to just include <Python.h>. Looks like that works on both platforms. Any comment on that?Overdrive
+1 that was flawless! *can you point me to a kind of "GCC configuration cheatsheet" or something like that?Mixup
N
2

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

Nero answered 19/5, 2017 at 17:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.