为所有用户更改python和python3的默认版本

时间:2020-10-04 15:18:55

标签: python-3.x ubuntu

我正在使用的服务器(Ubuntu 18.3)安装了python 2.7和3.6,最近我必须为一个项目安装3.8。不幸的是,这弄乱了默认版本,我无法修复它。

我得到的是什么

$ python2 --version
Python 2.7.17
$ python3 --version
Python 3.8.5
$ python --version
Python 3.6.9

我想要什么:

$ python2 --version
Python 2.7.17
$ python3 --version
Python 3.6.9
$ python --version
Python 2.7.17

我尝试过:

$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.8   2         auto mode
* 1            /usr/bin/python3.6   1         manual mode
  2            /usr/bin/python3.8   2         manual mode

$ sudo update-alternatives --config python3
update-alternatives: error: no alternatives for python3

我还在/ usr / bin中看到了python3的符号链接,但它看起来是正确的:

$ /usr/bin/python3 --version
Python 3.6.9

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

现在,在 Ubuntu 20.04 LTS 中,默认的python3作为python3可以通过以下命令轻松设置:

$ sudo apt install python-is-python3
$ python --version
Python 3.8.5