首先下载python和解压包

wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
tar zxvf Python-3.9.5.tgz
cd Python-3.9.5/

安装必须的依赖

yum -y install gcc zlib* libffi-devel
或者
dnf -y install gcc zlib* libffi-devel

开始make安装

./configure --prefix=/usr/local/python3 --enable-optimizations
make && make install

删除原先的Python3和pip3,并进行链接

rm -rf /usr/bin/python3
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
rm -rf /usr/bin/pip3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

查看Python3和Pip3是否正确的被安装:

python3 --version
pip3 --version

centos python2.7升级到3.7 centos 8 python 升级_centos