开始:
1、查看原有Python
whereis python
2、切换目录
cd /usr/bin/
ll python*
一、安装相关的依赖包,用于编译
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
二、安装pip
yum -y install epel-release
yum install python-pip
pip install wget
三、下载Python安装包
wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tar.xz
四、解压
xz -d Python-3.9.6.tar.xz
tar -xf Python-3.9.6.tar
五、编译
cd Python-3.9.6
./configure prefix=/usr/local/python3
make && make install
六、安装依赖zlib、zlib-deve
yum install zlib zlib
yum install zlib zlib-devel
七、添加软链接,将原来的链接备份
mv /usr/bin/python /usr/bin/python.bak
八、添加新安装的软连接
ln -s /usr/local/python3/bin/python3.9 /usr/bin/python3
九、测试
python3 -V
十、更改yum配置 把第一行的#! /usr/bin/python 修改为 #! /usr/bin/python2
vi /usr/bin/yum
十一、修改其他 #! /usr/bin/python 修改为: #! /usr/bin/python2
vi /usr/libexec/urlgrabber-ext-down
十二、移除旧的软连接并添加新的软连接
rm -rf /usr/bin/python
ln -s /usr/local/python3/bin/python3 /usr/bin/python
十三、查看版本
python -V