在Cen上找不到Python.h文件

2024-04-29 02:09:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在CentOS机器上编译一个用C编写的Python扩展。我得到了

error: Python.h: No such file or directory

它在ubuntu上运行得很好,在那里我使用apt-get安装了python-dev。

我试着用

yum install python-devel

但它已经安装好了。如何修复此错误?


Tags: installornodev机器getubuntuapt
3条回答

在我的系统中,Python.h头文件位于路径/usr/include/python2.6/中。由于预处理器默认不搜索此路径,因此必须将其添加到要搜索的路径列表中。这是通过编译器的-I选项完成的,如下所示:

$ gcc -I/usr/include/python2.6 source.c -o program

将上面的路径更改为系统上的实际路径。您可以使用注释中建议的^{}命令找到它,也可以使用^{}命令找到它(如果已安装)。

  • 对于CentOS 7.4
    • Python 3.6.6yum -y install python36-devel
    • Python 2yum -y install python-devel
  • 对于Ubuntu
    • Python 3.6apt-get install libpython3.6-dev

如果您使用python3,那么可以为此安装python34 devel

它在EPEL Repository上可用,并且有python34-devel package可用

你只要运行这个命令就可以安装它

yum install python34-devel

希望对你有帮助

*注意此时python34-devel是python 3的最新版本

相关问题 更多 >