我试图使用C扩展名文件构建共享库,但首先必须使用以下命令生成输出文件:
gcc -Wall utilsmodule.c -o Utilc
执行命令后,我收到以下错误消息:
> utilsmodule.c:1:20: fatal error: Python.h: No such file or directory
compilation terminated.
我已经在互联网上尝试了所有建议的解决方案,但问题仍然存在。我对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或libpython-all-dev是(apt)安装的第一件事,但如果这对我的情况没有帮助,我建议您通过sudo apt-get-install libffi-dev和sudo pip-install cffi安装外部函数接口包。
这将有助于解决问题,尤其是当您看到错误为/from c/_cffi_backend.c:2:20:致命错误:Python.h:没有这样的文件或目录时。
其他回答
在Ubuntu上,我运行的是Python 3,我必须安装
sudo apt-get install python3-dev
如果要使用未链接到python3的Python版本,请安装相关的python3.x-dev包。例如:
sudo apt-get install python3.5-dev
对于OpenSuse的同志们:
sudo zypper install python3-devel
有时,即使在安装python dev之后,错误仍然存在,如果缺少“gcc”,请检查错误。
第一次下载,如中所述https://stackoverflow.com/a/21530768/8687063,然后安装gcc
对于apt(Ubuntu、Debian…):
sudo apt-get install gcc
对于yum(CentOS,RHEL…):
sudo yum install gcc
对于dnf(Fedora…):
sudo dnf install gcc
对于zypper(openSUSE…):
sudo zypper in gcc
对于apk(Alpine…):
sudo apk gcc
这不是同一种情况,但它也适用于我,现在我可以在Python3.5中使用SWIG:
我试图编译:
gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/
使用Python 2.7可以很好地工作,而不是使用我的3.5版本:
exist_wrap.c:147:21:致命错误:Python.h:不存在el archivo o eldirectorio编译已终止。
在Ubuntu 16.04安装中运行后:
sudo apt-get install python3-dev # for python3.x installs
现在我可以毫无问题地编译Python3.5:
gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/
当我尝试在CentOS 7上使用Python3.6安装ctds时发生此错误。我完成了这里提到的所有技巧,包括yum安装python34-devel。问题是Python.h在/usr/include/python3.4m中找到,但在/usr/include/python3.6m中找不到。我尝试使用--global选项指向include-dir(pip3.6 install--global option=build_ext--global options=“--include-dirs=/usr/include/pyton3.4m”ctds)。这导致在链接ctd时找不到lpython3.6m。
最后,工作是修复Python3.6的开发环境,需要使用include和libs进行纠正。
yum -y install https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/python36u-libs-3.6.3-1.ius.centos7.x86_64.rpm
Python.h需要位于gcc的include路径中。无论使用哪种版本的python,例如,如果它是3.6,那么它通常应该在/usr/include/python3.6m/python.h中。