Find the answer to your Linux question:
Results 1 to 4 of 4
I am trying to embed some C code in Python, and I have a C program that includes Python.h. When I try to compile it it says "fatal error: Python.h: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2011
    Posts
    11

    Python.h not found


    I am trying to embed some C code in Python, and I have a C program that includes Python.h. When I try to compile it it says
    "fatal error: Python.h: No such file or directory"
    though I have Python.h in /usr/include/python2.7. Anyone know what's wrong?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,737
    It depends upon two things. 1) is what include directories you have specified in your makefile with the -I <dir> flag, and 2) is how you specified the include file with the #include <file> directive in your code. If #2 was "#include <python.h>", then you need the flag "-I /usr/include/python2.7" in the CFLAGS section of your makefile.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Sep 2011
    Posts
    11
    Then would I have to use make to compile this C program, or run the python program that calls it? Or can I still use gcc/python. And can you tell me where makefile is?

    Thanks.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,737
    You need to build the C code first. As for the makefile for your C code, that depends. Usually it is created dynamically by either a configure script (autoconf), or a set of cmake rules. These are two common methods used to interrogate the operating system for installed software to see what it is capable of, creating the appropriate Makefile with the flags needed to build the tool in question. So what is this program that you are trying to get to work with Python?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •