fatal error: Python.h: No such file or directory

This question already has an answer here:

  • I have Python on my Ubuntu system, but gcc can't find Python.h 12 answers

  • Looks like you haven't properly installed the header files and static libraries for python dev. Use your package manager to install them system-wide.

    For apt ( Ubuntu, Debian... ):

    sudo apt-get install python-dev   # for python2.x installs
    sudo apt-get install python3-dev  # for python3.x installs
    

    For yum ( CentOS, RHEL... ):

    sudo yum install python-devel   # for python2.x installs
    sudo yum install python34-devel   # for python3.4 installs
    

    For dnf ( Fedora... ):

    sudo dnf install python2-devel  # for python2.x installs
    sudo dnf install python3-devel  # for python3.x installs
    

    For zypper ( openSUSE... ):

    sudo zypper in python-devel   # for python2.x installs
    sudo zypper in python3-devel  # for python3.x installs
    

    On Ubuntu, I was running Python 3 and I had to install

    sudo apt-get install python3-dev
    

    If you want to use a version of Python that is not linked to python3, install the associated python3.x-dev package. For example:

    sudo apt-get install python3.5-dev
    

    Two things you have to do.

    Install development package for Python, in case of Debian/Ubuntu/Mint it's done with command:

    sudo apt-get install python-dev
    

    Second thing is that include files are not by default in the include path, nor is Python library linked with executable by default. You need to add these flags (replace Python's version accordingly):

    -I/usr/include/python2.7 -lpython2.7 
    

    In other words your compile command ought to be:

    gcc -Wall -I/usr/include/python2.7 -lpython2.7  utilsmodule.c -o Utilc 
    
    链接地址: http://www.djcxy.com/p/26310.html

    上一篇: 无法使用PIP和setup.py安装Python加密包

    下一篇: 致命错误:Python.h:没有这样的文件或目录