1.安装依赖包
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel -y
2.官网下载源码
wget https://www.python.org/ftp/python/3.7.12/Python-3.7.12.tgz
3.解压编译
tar -zxvf Python-3.7.0.tgz
cd Python-3.7.0
./configure
make&&make install
配置国内源,没有文件自己创建
vi %HOME%/.pip/pip.conf
[global]
trusted-host = mirrors.aliyun.com
index-url = https://mirrors.aliyun.com/pypi/simple/
第4、5步可以不做,使用时用python3命令即可
4.软连接
mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/bin/python3 /usr/bin/python
mv /usr/bin/pip /usr/bin/pip.bak
ln -s /usr/local/bin/pip3 /usr/bin/pip
5.配置yum python2.7
vim /usr/libexec/urlgrabber-ext-down
vi /usr/bin/yum
#将第一行修改
#! /usr/bin/python
改成
#! /usr/bin/python2.7