我试图使用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没有问题。我设法在我的机器上找到了该文件。
当前回答
Cygwin解决方案
您需要安装python2-devel或python3-devel包,具体取决于您使用的Python版本。
您可以使用Cygwin.com上的32位或64位setup.exe(取决于您的安装)快速安装它。
示例(如果需要,请修改setup.exe的文件名和Python的主要版本):
$ setup.exe -q --packages=python3-devel
您还可以查看我的另一个答案,以获得从命令行安装Cygwin软件包的更多选项。
其他回答
当您尝试删除python3.5并安装python3.6时,通常会出现这种情况。
因此,当使用python3(即python3-V=>python3.6)安装某些所需的包时,python3.5标头将显示此错误。
通过安装python3.6-dev模块解决。
我设法解决了这个问题,并在一个命令中生成.so文件
gcc -shared -o UtilcS.so
-fPIC -I/usr/include/python2.7 -lpython2.7 utilsmodule.c
尝试apt文件。很难记住丢失文件所在的包名。它是通用的,适用于任何包文件。
例如:
root@ubuntu234:~/auto# apt-file search --regexp '/Python.h$'
pypy-dev: /usr/lib/pypy/include/Python.h
python2.7-dbg: /usr/include/python2.7_d/Python.h
python2.7-dev: /usr/include/python2.7/Python.h
python3.2-dbg: /usr/include/python3.2dmu/Python.h
python3.2-dev: /usr/include/python3.2mu/Python.h
root@ubuntu234:~/auto#
现在你可以做出专家猜测,从中选择哪一个。
这不是同一种情况,但它也适用于我,现在我可以在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/
Cygwin解决方案
您需要安装python2-devel或python3-devel包,具体取决于您使用的Python版本。
您可以使用Cygwin.com上的32位或64位setup.exe(取决于您的安装)快速安装它。
示例(如果需要,请修改setup.exe的文件名和Python的主要版本):
$ setup.exe -q --packages=python3-devel
您还可以查看我的另一个答案,以获得从命令行安装Cygwin软件包的更多选项。