系统相关
首页 > 系统相关> > 更改Ubuntu默认的Python版本

更改Ubuntu默认的Python版本

作者:互联网

查看可用版本

ls /usr/bin/python*
/usr/bin/python   /usr/bin/python2.7  /usr/bin/python3.5   /usr/bin/python3m
/usr/bin/python2  /usr/bin/python3    /usr/bin/python3.5m

查看可替换版本信息

update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.5

如果显示如下信息:

{%r%}
update-alternatives: error: no alternatives for python
{%endr%}

则表示Python 的替换版本尚未被update-alternatives 命令识别。想解决这个问题,我们需要更新一下替换版本,将Python2.7和python3.5放入其中。执行以下命令:

{%g%}
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
{%endg%}

切换版本

sudo su
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 <enter> to keep the current choice[*], or type selection number: 

输入1,则切换到python2.7
然后查看一下python版本

python --version
Python 2.7.12

参考链接:
https://www.cnblogs.com/Yanfang20180701/p/10588087.html

标签:bin,Python,alternatives,update,默认,python,python3.5,usr,Ubuntu
来源: https://www.cnblogs.com/chendeqiang/p/12861729.html