1

I apologize for this newbie question. I am currently looking to embedded a small python code into a main C code. It has been suggested to use #include <Python.h> at the header. I have already done so and that my Ubuntu12-0.4 machine also has python-dev installed.

By running locate Python.h, I got /usr/include/python2.7/Python.h.

However, when I include Python.h into my C program, it still gives me fatal error: python.h: No such file or directory.

So Python.h hasn't been include in the Makefile. But I have no idea how to do so. Looking into my package list I have: Makefile.am,Makefile.in, and Makefile.


In Makefile.am:

ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = MIGRATION README.rst libmodbus.spec
SUBDIRS = src doc tests

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libmodbus.pc

In Makefile.in, the first line says

# Makefile.in generated by automake 1.14.1 from Makefile.am.

Should I also include the complete description of Makefile.in to here? I am not sure how should I proceed.

andy_tse
  • 189
  • 1
  • 5
  • 13
  • I don't know about `automake`, but when you invoke `g++`, I think there should be an option `-L/usr/include/python2.7`. (`/usr/include` is appended to the search list automatically, but I don't think this is recursive.) – James Kanze Jan 31 '15 at 18:03
  • @JamesKanze `-I /usr/include/python2.7` Uppercase `i` -- not `L` -- that's for libraries. Or am I wrong ? – Sylvain Leroux Jan 31 '15 at 18:31
  • 1
    @SylvainLeroux You're right. It should be `-I`. You may need a `-R` as well, or something to tell the linker and the executable where to look for the library as well (unless it is in `/usr/lib`). I don't have a Unix system handy to check, but you might also verify the capitalization; your error message says `python.h`, not `Python.h`. – James Kanze Jan 31 '15 at 18:47
  • So, do I just add that to my Makefile.am? – andy_tse Jan 31 '15 at 18:56
  • You're probably looking at the wrong `Makefile.am`. Most likely you want the one in `src` if that is where your program is being compiled. You can try setting `AM_CPPFLAGS = -I/usr/include/python2.7` in that file and regenerate the Makefiles. That's probably only appropriate for an experimental patch, though - the "right" way to do it is generally to modify `configure.ac` to have autoconf locate Python and set up the proper flags. – rhashimoto Jan 31 '15 at 20:00

1 Answers1

0

I've got the same error, try this:

gcc -I/usr/include/python2.7 yoursource.c -o yourprogram

This solution is from: Can't find Python.h file on CentOS

Community
  • 1
  • 1
Denny
  • 163
  • 2
  • 9