Results 1 to 4 of 4

Thread: Can't find Python.h already installed python-dev

  1. #1
    Join Date
    Apr 2008
    Beans
    4

    Can't find Python.h already installed python-dev

    Hi,

    I'm a newbie programmer trying to call C functions from Python and when I #include <Python.h> and "gcc spam.c" I get the compiler message, "fatal error: Python.h: No such file or directory compilation terminated"

    Of course I Googled the problem and everyone says "sudo apt-get install python-dev" I did this though and I still get the same error message.

    Also I tried "find Python.h" and no such file or directory. I even manually looked in /usr/lib/Python2.7 and its not there.

    I'm running Ubuntu12.04 and Python2.7.3. 64-bit if it matters.

    Thanks!

  2. #2
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: Can't find Python.h already installed python-dev

    python headers in subfolders, normally /usr/include/python2.7 and /usr/include/x86_64-linux-gnu/python2.7
    use e.g. python-config to get them:
    Code:
    gcc $(python-config --includes) file.c
    from within python you can get the path with distutils:
    Code:
    from distutils.sysconfig import get_python_inc
    incdirs = [get_python_inc(), get_python_inc(plat_specific=True)]
    Last edited by MadCow108; January 27th, 2013 at 04:50 PM. Reason: fix syntax error

  3. #3
    Join Date
    Apr 2008
    Beans
    4

    Re: Can't find Python.h already installed python-dev

    You're right. Python.h is in /usr/include/python2.7 on my machine.

    Code:
    incdirs = [get_python_inc(), get_python_inc(plat_specific=True)])
    gave me a syntax error.

  4. #4
    Join Date
    Apr 2008
    Beans
    4

    Re: Can't find Python.h already installed python-dev

    Adding the correct path, as Mad Cow pointed out, solved the problem.

    Code:
    $ C_INCLUDE_PATH=/usr/include/python2.7
    $ export C_INCLUDE_PATH
    Thanks!

Bookmarks

Posting Permissions

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