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

  • 问题:
  • 我尝试使用C扩展名文件构建共享库,但首先必须使用以下命令生成输出文件:

    gcc -Wall utilsmodule.c -o Utilc

    执行命令后,我收到以下错误消息:

    > utilsmodule.c:1:20: fatal error: Python.h: No such file or directory
    compilation terminated.

    我在网上试过所有建议的解决办法,但问题仍然存在。我对Python.h没有问题。我设法在我的机器上找到了文件

  • 答案:
  • 看起来您没有正确安装python dev的头文件和静态库。请使用包管理器在系统范围内安装它们。在

    对于aptUbuntu,Debian…):

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

    对于yumCentOS,RHEL…):

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

    对于dnfFedora…):

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

    对于zypperopenSUSE…):

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

    对于apk阿尔卑斯…):

    # This is a departure from the normal Alpine naming
    # scheme, which uses py2- and py3- prefixes
    sudo apk add python2-dev # for python2.x installs
    sudo apk add python3-dev # for python3.x installs

    对于apt cygCygwin…):

    apt-cyg install python-devel   # for python2.x installs
    apt-cyg install python3-devel # for python3.x installs