Python.h No such file...

S

Steve Doody

When I add #include <Python.h> to a
header file, GCC tells me, No such file or directory.

Am trying to learn how to combine C++ and Python.
Using SuSE 9.0 Linux, 2.4.21-231-default
GCC 3.3.1
Python 2.3.4 (Just built on the box successfully)

My problem is is probably because I am
ignorant of correct GCC setup and config for Python.
I am using the default SuSE GCC setup unchanged.

I installed Python from source to /usr/local/Python-2.3.4/
The Include directory, and everything else, is there.

I have hunted through the info docs, particularly GCC, but cannot see
where I change the config to fix this...?

Tried specifying the full path, #include ".../Python.h"
but then lots of related stuff breaks cos its not found...

The compile is a simple/test exercise
and works without the Python.h header line.

Posted this first to the comp.lang.C++ newsgroup, cos it looks like a
GCC item, but no joy.

Appreciate any suggestions or hints as to what to look for.

Steve Doody.
SD AT ACM DOT ORG
 
S

Skip Montanaro

Steve> When I add #include <Python.h> to a
Steve> header file, GCC tells me, No such file or directory.

Steve> Am trying to learn how to combine C++ and Python.
Steve> Using SuSE 9.0 Linux, 2.4.21-231-default
Steve> GCC 3.3.1
Steve> Python 2.3.4 (Just built on the box successfully)

Make sure you have the relevant -devel package installed from your
installation media.

Skip
 
H

Heiko Wundram

Am Dienstag, 27. Juli 2004 03:41 schrieb Steve Doody:
When I add #include <Python.h> to a
header file, GCC tells me, No such file or directory.

Well you're trying to include a global header called Python.h using this
format. Now, gcc never looks for global headers in directories other
than /usr/include and /usr/local/include per default, that's why you're
seeing "No such file or directory".
I installed Python from source to /usr/local/Python-2.3.4/
The Include directory, and everything else, is there.

Does this mean you set --prefix to /usr/local/Python-2.3.4/ on configure? If
yes, try specifying -I/usr/local/Python-2.3.4/include/python2.3 on the gcc
line, and it'll start looking for global headers in that directory (which
should contain Python.h).

If you just took the default route of installing it to /usr/local/, add
-I/usr/local/include/python-2.3 to the gcc line.

If you installed Python to /usr/local/Python-2.3.4, gcc will not only not find
the python includes, but will also not find the python libraries which are
needed for linking. So, you'll also have to specify
-L/usr/local/Python-2.3.4/lib on the gcc command line. This is not necessary
if you installed it to /usr/local/

So, compiling your file should be done in the following way:

gcc -I/usr/local/Python-2.3.4/include/python2.3 \
-L/usr/local/Python-2.3.4/lib -lpython -o test test.c

Or something of the like.

HTH!

Heiko.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top