Linux python2.7 升级到3.5

检查python版本:

python --version
Python 2.7.12

方法一 (推荐)

1、检查Python的替代版本是否被update-alternatives 命令识别

root@JoJo:~# update-alternatives --list python
update-alternatives: error: no alternatives for python

报错表示没有

2、更新替换列表

root@JoJo:~# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
root@JoJo:~# update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python (python) in auto mode

查看:

root@JoJo:~# update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.5

3、选择版本

root@JoJo:~# update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.5   2         auto mode
  1            /usr/bin/python2.7   1         manual mode
  2            /usr/bin/python3.5   2         manual mode

Press  to keep the current choice[*], or type selection number: 0

检查版本号:

root@JoJo:~# python --version
Python 3.5.2

替换成功

4、删除旧版本 (可选)

update-alternatives --remove python /usr/bin/python2.7

不推荐直接删除软链接,反正update-alternatives可以配置...就别删了

方法二

1、检查系统是否默认安装了3.5

root@JoJo:~# whereis python3.5
python3: /usr/bin/python3.5 /usr/bin/python3.5m /usr/bin/python3 /usr/lib/python3.5 /usr/lib/python3 /etc/python3.5 /etc/python3 /usr/local/lib/python3.5 /usr/share/python3 /usr/share/man/man1/python3.1.gz

已安装
也可用:

root@JoJo:~# ls /usr/bin/python*
/usr/bin/python   /usr/bin/python2.7         /usr/bin/python2-config  /usr/bin/python3.5   /usr/bin/python3m
/usr/bin/python2  /usr/bin/python2.7-config  /usr/bin/python3         /usr/bin/python3.5m  /usr/bin/python-config

2、删除2.7的Python链接文件

rm -rf /usr/bin/python

3、新建指向Python3.5的软链接

ln -s /usr/bin/python3.5 /usr/bin/python

4、添加环境变量

PATH=/usr/bin:$PATH

替换完成

你可能感兴趣的:(Linux python2.7 升级到3.5)