4

I'm trying to figure out how to compile Python modules in C (http://docs.python.org/extending/extending.html), but the Python.h header file appears to be missing.

I've installed all the python development headers (I have Python-dev, python2.7-dev, python2.6-dev, python-all-dev) but gcc is still reutrning the error:

fatal error: Python.h: No such file or directory compilation terminated. 

Any idea where I'm going wrong here? Also is there an argument I need to add to gcc for Python.h (and what is it?).

3
  • 1
    Can you tell us what OS? Commented May 16, 2012 at 16:26
  • Did you try Geoff's suggestion? If it didn't work, add a comment to his answer to say what happened. Commented May 17, 2012 at 21:17
  • Still trying to figure it out. The documentation on this stuff is awful. Commented May 18, 2012 at 11:14

1 Answer 1

10

You need to use python-config to determine the compile time and link time flags.

When compiling:

gcc -c `python-config --cflags` somefile.c 

When linking:

gcc -o libfoo.so -shared `python-config --ldflags` 

Though you really ought to think about using distutils as described in Building C and C++ Extensions with distutils

Sign up to request clarification or add additional context in comments.

1 Comment

Sorted, thanks. Was going in the complete wrong direction there.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.