我试图在Ubuntu 16.04中将默认的python版本设置为python3。默认值是python2(2.7)。我遵循以下步骤:

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3

但是对于第二个语句,我得到了如下错误,

rejeesh@rejeesh-Vostro-1015:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs <link> <name> <path> <priority>

Use 'update-alternatives --help' for program usage information.   

当前回答

获取python路径

ls /usr/bin/python*

然后设置你的python版本

alias python="/usr/bin/python3"

其他回答

你没有包括优先级参数

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 5

你可以用你想要的任何优先级替换5。优先级高的备选方案优先于优先级低的备选方案。

只需删除python-is-python2:

sudo apt purge python-is-python2

并安装python-is-python3:

sudo apt install python-is-python3

它将自动转换到新python3的过程。你也可以选择在以后去掉剩下的包:

sudo apt autoremove && sudo apt autoclean

为Linux终端中的默认python设置优先级:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1

这里,我们将python3的优先级设置为10,将python2的优先级设置为1。这将使python3成为默认的python。如果你想将Python2作为默认值,那么将Python2的优先级设置为高于python3

获取python路径

ls /usr/bin/python*

然后设置你的python版本

alias python="/usr/bin/python3"

要更改为python3,可以在终端别名python=python3中使用以下命令。