Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python.h header missing

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?).

like image 790
James Jenkinson Avatar asked Dec 27 '22 00:12

James Jenkinson


1 Answers

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

like image 152
Geoff Reedy Avatar answered Jan 11 '23 04:01

Geoff Reedy