首先下载源码包
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
解压
tar xf Python-3.7.2.tgz
cd Python-3.7.2.tgz
安装依赖包
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel gcc gcc-lib gcc-c++ zlib libffi-devel
./configure --prefix=/usr/local/python3
make && make install
备份原有的python以便后期恢复
mv /usr/bin/python mv/usr/bin/python2.7.5
接下来需要修改yum配置文件,否则yum将无法使用
vi /usr/bin/yum
把配置文件头#!/usr/bin/python 改成#!/usr/bin/python2.7.5
之后建立新的链接 ln -s /usr/local/python3/bin/python3.7 /usr/bin/python
最后检查python指向是否成功
python -V