在 CentOS 上找不到 Python.h 文件

时间:2023-04-16
本文介绍了在 CentOS 上找不到 Python.h 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试在 CentOS 机器上编译用 C 编写的 Python 扩展.我得到了

I am trying to compile a Python extension written in C on a CentOS machine. I am getting

error: Python.h: No such file or directory

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

It works fine on ubuntu, where I have python-dev installed using apt-get.

我尝试使用安装 python-devel

I tried installing python-devel using

yum install python-devel

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

but it is already installed. How do I fix this error?

推荐答案

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

On my system the Python.h header file is in the path /usr/include/python2.6/. As this path is not searched by the pre-processor by default, you have to add it to the list of paths to search. This is done with the -I option to the compiler, like this:

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

将上面的路径更改为系统上的实际路径.您可以使用 find 命令中的建议找到它locate 命令(如果已安装)的注释.

Change the path above to the actual path on your system. You can find it either with the find command as proposed in a comment, of with the locate command if it's installed.

这篇关于在 CentOS 上找不到 Python.h 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!