【问题标题】:Can't find Python.h file on CentOS在 CentOS 上找不到 Python.h 文件
【发布时间】:2012-09-04 23:40:46
【问题描述】:

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

error: Python.h: No such file or directory

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

我尝试使用安装 python-devel

yum install python-devel

但它已经安装了。如何解决此错误?

【问题讨论】:

  • 打开一个终端并输入find / -name Python.h 2>/dev/null 有什么结果吗?
  • 还有你用的是什么版本的 CentOS?
  • 我在CentOS Linux release 7.1.1503yum install python-devel 上遇到了同样的问题。

标签: python c centos


【解决方案1】:

如果你使用 python3,你可以为此安装 python34-devel

EPEL Repository 上可用,python34-devel package 可用

您只需运行此命令即可安装它

yum install python34-devel

希望对你有帮助

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

【讨论】:

  • 2.7 => python-devel 3.4 => python34-devel 3.6 => python36-devel
【解决方案2】:

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

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

将上面的路径更改为系统上的实际路径。您可以使用评论中建议的 find 命令找到它,如果已安装,则可以使用 locate 命令。

【讨论】:

  • 啊,对不起,我明白了,是c源文件,对不起
【解决方案3】:
  • CentOS 7.4
    • Python 3.6.6yum -y install python36-devel
    • Python 2yum -y install python-devel
  • Ubuntu
    • Python 3.6: apt-get install libpython3.6-dev

【讨论】:

  • yum -y install python3-devel 将为该版本的 CentOS 安装最新的可用 python3 版本。
  • 我能够通过yum -y install python3-devel 解决问题并构建我的 docker 映像。以前我安装了python3-dev 并且能够构建我的图像。最近有改名吗?
【解决方案4】:

我有一个类似的问题,默认 Python 是 2.7,但 pip 是针对 3.4 运行的,我想使用 2.7。所以我做了:yum remove python34-pipyum install python2-pip。解决了!

【讨论】:

    【解决方案5】:

    我也有类似的问题。

    ./python/py_defines.h:39:20:致命错误:Python.h:没有这样的文件或 目录

    而 find 命令显示 python.h 存在。

    上述解决方案不起作用,但以下命令执行对我有用。

    yum install python27-python-devel.x86_64
    

    没什么不同,但浪费了很多时间。

    【讨论】:

      【解决方案6】:

      在 Centos6.X 上安装 python3.4(包括 pip)和 python3.4-dev 软件包:

      yum install http://dl.iuscommunity.org/pub/ius/stable/CentOS/6/x86_64/python34u-3.4.2-1.ius.centos6.x86_64.rpm
      yum install http://dl.iuscommunity.org/pub/ius/stable/CentOS/6/x86_64/python34u-devel-3.4.2-1.ius.centos6.x86_64.rpm
      

      【讨论】:

        【解决方案7】:

        这取决于你拥有的 Python!

        你需要一个dev的包,你有的Python X.X.X版本X.X.X,你可以搜索https://centos.pkgs.org/7/ius-x86_64

        例如,如果您有 IUS 的 Python 3.6.5,则需要安装 https://centos.pkgs.org/7/ius-x86_64/python36u-devel-3.6.5-1.ius.centos7.x86_64.rpm.html

        【讨论】:

          【解决方案8】:

          适用于 centos 8+

          dnf install -y python3-devel
          

          【讨论】:

            猜你喜欢
            • 2014-10-20
            • 1970-01-01
            • 2020-01-21
            • 1970-01-01
            • 2016-09-17
            • 1970-01-01
            • 2015-05-13
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多