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

gcc -Wall utilsmodule.c -o Utilc

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

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

我已经在互联网上尝试了所有建议的解决方案,但问题仍然存在。我对Python.h没有问题。我设法在我的机器上找到了该文件。


当前回答

AWS EC2安装运行python34:

sudo yum安装python34-devel

其他回答

Cygwin解决方案

您需要安装python2-devel或python3-devel包,具体取决于您使用的Python版本。

您可以使用Cygwin.com上的32位或64位setup.exe(取决于您的安装)快速安装它。

示例(如果需要,请修改setup.exe的文件名和Python的主要版本):

$ setup.exe -q --packages=python3-devel

您还可以查看我的另一个答案,以获得从命令行安装Cygwin软件包的更多选项。

AWS EC2安装运行python34:

sudo yum安装python34-devel

如果您使用tox在多个版本的Python上运行测试,则可能需要为正在测试的每个版本的Python安装Python开发库。

sudo apt-get install python2.6-dev 
sudo apt-get install python2.7-dev 
etc.

如果您使用带有3.6 python的virtualenv(现在是边缘),请确保安装匹配的python 3.6 dev sudo apt-get install python3.6-dev,否则执行sudo python3 dev将安装python dev 3.3.3-1,这不会解决问题。

这不是同一种情况,但它也适用于我,现在我可以在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/