欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

解决Python.h: No such file or directory

程序员文章站 2024-02-21 23:25:10
...

具体报错信息如下:

In file included from src/hiredis.c:1:0:
src/hiredis.h:4:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1

报错是找不到Python.h 文件,主要是 python-dev 或 python-devel 包没有安装导致了,而我的系统是麒麟 ARM架构:

uname -a
Linux root 4.19.90-23.6.v2101.ky10.aarch64 #1 SMP Wed Mar 17 14:45:17 CST 2021 aarch64 aarch64 aarch64 GNU/Linux

安装的包名和安装命令有所不同,正确命令如下:

dnf install python3-devel  # 我这里用的是python3

下面是其他系统使用到安装命令:

For apt (Ubuntu, Debian...):
sudo apt-get install python-dev   # for python2.x 
sudo apt-get install python3-dev  # for python3.x 
-------------------------------------------------
For yum (CentOS, RHEL...):
sudo yum install python-devel    # for python2.x 
sudo yum install python3-devel   # for python3.x 
-------------------------------------------------
For dnf (Fedora, Kylin V10...):
sudo dnf install python2-devel  # for python2.x 
sudo dnf install python3-devel  # for python3.x 
-------------------------------------------------
For zypper (openSUSE...):
sudo zypper in python-devel   # for python2.x 
sudo zypper in python3-devel  # for python3.x 
-------------------------------------------------
For apk (Alpine...):
sudo apk add python2-dev  # for python2.x 
sudo apk add python3-dev  # for python3.x 
-------------------------------------------------
For apt-cyg (Cygwin...):
apt-cyg install python-devel   # for python2.x 
apt-cyg install python3-devel  # for python3.x 
-------------------------------------------------
For yum AWS API (centOS)
yum install python27-devel   # for python2.x
yum install python37-devel   # for python3.x 
-------------------------------------------------
For other
apt install libpython3.7-dev
apt install libpython3-all-dev
-------------------------------------------------

由于面对的操作系统不同,python版本的不同,使用的安装命令也不同,总体总结为
安装命令:apt-get、apt、yum、apt-cyg、apk、zypper、dnf
包名:python-devel、python-dev、libpython-dev、libpython-all-dev
版本:2、3、2.7、3.7、27、37等等
上面的三项,就可以组成很多种命令,实在不知道是哪个,就试吧。祝你成功!