在 CentOS 上找不到 Python.h 文件

2023-04-16Python开发问题
38

本文介绍了在 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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

pandas 有从特定日期开始的按月分组的方式吗?
Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)...
2024-08-22 Python开发问题
10

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10