解决Python.h: No such file or directory

具体报错信息如下:

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等等
上面的三项,就可以组成很多种命令,实在不知道是哪个,就试吧。祝你成功!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值