CentOS7 下升级Python版本

*参考地址:https://www.cnblogs.com/ech2o/p/11748464.html

1.下载目标python版本压缩包(我的目录是/download)

wget http://npm.taobao.org/mirrors/python/3.8.0/Python-3.8.0.tgz

2.解压压缩包到/usr/local/

tar -zxvf Python-3.8.0.tgz -C /usr/local/

3.编译与安装

3.1 切换到cd /usr/local
3.2 创建文件夹 mkdir python3
3.3 切换目录cd /usr/local/Python-3.8.0
3.4 生成makefile文件./configure --prefix=/usr/local/python3
3.5 编译make
3.6 安装make install

4.创建python3软链(建议直接去第5步)

4.1ln -s /usr/local/python3/bin/python3 /usr/bin/python3
4.2ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
报错ln: failed to create symbolic link ‘/usr/bin/python3’: File exists
解决方法,覆盖之前:用命令ln -sf /usr/local/python3/bin/python3 /usr/bin/python3
ln -sf /usr/local/python3/bin/pip3 /usr/bin/pip3

5.覆盖现有python,启动python时指向python3.8

1.备份旧python与pip
mv /usr/bin/python /usr/bin/python2_old
mv /usr/bin/pip /usr/bin/pip2_old
2.修改软链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

6.收尾,安装之后yum不能使用

1.编辑vim /usr/bin/yum 将第一行#!/usr/bin/python换成#!/usr/bin/python2.7
2.编辑vim /usr/libexec/urlgrabber-ext-down将第一行#!/usr/bin/python换成#!/usr/bin/python2.7

你可能感兴趣的:(CentOS7 下升级Python版本)