1、在Linux系统中,需要自行下载编译程序,下载python3的包之前,要先安装相关的依赖包,用于下载编译python3。
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
2、添加epel扩展源。
yum -y install epel-release
3、安装pip
yum install python-pip
4、用wget下载python3的源码包
wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tar.xz
5、编译python3源码包,解压
xz -d Python-3.9.6.tar.xz
tar -xf Python-3.9.6.tar
6、手动编译
cd Python-3.9.6
./configure prefix=/usr/local/python3
make && make install
7、安装依赖zlib、zlib-deve
yum install zlib zlib
yum install zlib zlib-devel
8、添加软链接,将原来的链接备份
mv /usr/bin/python /usr/bin/python.bak
9、添加python3的软链接
ln -s /usr/local/python3/bin/python3.9 /usr/bin/python3
10、测试是否安装成功
python3 -V
11、更改yum配置
vi /usr/bin/yum
将第一行的#! /usr/bin/python修改为#! /usr/bin/python2
vi /usr/libexec/urlgrabber-ext-down
将第一行修改为:#! /usr/bin/python2
安装完成,启动python2、python3