Tomcat

Centos7 Python2 升级到Python3

2019-01-11  本文已影响0人  554d8b1ddfeb

1. 从Python官网到获取Python3的包, 切换到目录/usr/local/src

wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz

2. 使用命令如下命令进行解压缩:

xz -d Python-3.7.2.tar.xz

tar -xf Python-3.7.2.tar

3. 在/usr/local路径下创建目录--python37, 为第4步的安装目录

mkdir /usr/local/python37

4. 编译安装(会自动安装pip-7.1.2)

yum install -y zlib zlib-devel

yum install libffi-devel -y

复制代码

./configure --prefix=/usr/local/python37

make all

make install

make clean

make distclean

复制代码

5. 进入安装的绝对路径,检查是否安装成功

/usr/local/python37/bin/python3.7 -V

Python 3.7.2

6.查看环境变量,启动python时默认按照PATH的顺序进行查找,在/usr/bin中的python此时为Python2.7的。

echo $PATH

/usr/lib/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/gordon/bin

7.修改软连接,启动python时指向python3.7

(1) 备份python

mv /usr/bin/python /usr/bin/python.bak

(2) 修改软连接

ln -s /usr/local/python37/bin/python3 /usr/bin/python

8. 验证默认是否启动python3.7

python -V

 Python 3.7.2

9. 升级完python之后,yum就不好用了,需要修改/usr/bin/yum,改为使用python2.7

#!/usr/bin/python2.7

上一篇下一篇

猜你喜欢

热点阅读