1:安装python3的依赖
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
2:获取python3源码
wgethttps://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xzxz-d Python-3.6.6.tar.xztar-xf Python-3.6.6.tarcdPython-3.6.6
3:编译安装
## 注:--enable-optimizations 参数可不加。写在第一行,希望客官能注意到
./configure prefix=/usr/local/python3 --enable-optimizations
make
make install## 此处有小漫长的等待时间
4:备份python2,启用Python3
mv/usr/bin/python /usr/bin/python.bk
mv/usr/bin/pip /usr/bin/pip.bk
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
5:恢复yum的正常动作
修改/usr/bin/yum和/usr/libexec/urlgrabber-ext-down的首行脚本声明
vim/usr/bin/yum
# 第一行,把/usr/bin/python修改为/usr/bin/python2.7或者python2(2.7的链接)
vim /usr/libexec/urlgrabber-ext-down # 同上
7:验证,收工
python -V
yum
rm -f /usr/bin/python.bk
rm -f /usr/bin/pip.bk