操作系统:CentOS 7 Python版本:3.9.4

1、检查系统当前安装的Python版本

[root@localhost ~]# rpm -qa|grep python

2、下载安装包

有外网的直接执行wget下载,没有外网下载安装包,上传至服务器。

[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tgz

3、解压包

[root@localhost ~]# tar -xzvf Python-3.9.4.tgz

4、进入解压目录,并进行配置检查。

[root@localhost ~]# cd Python-3.9.4
[root@localhost Python-3.9.4]# ./configure --prefix=/usr/local/python3

5、编译并安装

[root@localhost Python-3.9.4]# make && make install
image.png

6、创建软链接

[root@localhost Python-3.9.4]# ln -s /usr/local/python3/bin/python3.9 /usr/bin/python3

7、测试

[root@localhost Python-3.9.4]# python3 --version
image.png
[root@localhost Python-3.9.4]# python3
image.png

错误

1、configure: error: no acceptable C compiler found in $PATH配置报错

image.png
原因:缺少gcc依赖包
解决方法:[root@localhost Python-3.9.4]# yum install gcc*