Centos Python2 升级到Python3

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

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

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

#xz -d Python-3.5.1.tar.xz
#tar -xf Python-3.5.1.tar

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

#mkdir /usr/local/python3.6

4. 编译安装

#cd /usr/local/src/Python-3.6.3
#./configure --prefix=/usr/local/python3.6
#make all
#make install
#make clean
#make distclean

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

/usr/local/python3.6/bin/python3.6 -V
 Python 3.6.3

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

#echo $PATH

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

1)备份python

#mv /usr/bin/python /usr/bin/python2.6.6

2)修改软连接

#ln -s /usr/local/python3.6/bin/python3 /usr/bin/python

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

#python -V
 Python 3.6.3

 

 

发表评论