我试图在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.   

当前回答

另一种非侵入性、仅限当前用户的方法是:

# First, make $HOME/bin, which will be automatically added to user's PATH
mkdir -p ~/bin
# make link actual python binaries
ln -s $(which python3) python
ln -s $(which pip3) pip

Python PIP将在一个新的shell中准备好。

其他回答

sudo rm /usr/bin/python3 #remove existing link
sudo ln /usr/bin/python3.8 /usr/bin/python3 # create a new link to the version of your choice

只需按照以下步骤将默认python更改为新升级的python版本。对我来说很管用。

sudo apt-install python3.7安装你想要的最新版本的python cd /usr/bin进入python安装的根目录 Sudo unlink python或Sudo unlink python3。取消当前默认python的链接 sudo ln -sv /usr/bin/python3.7 python链接新下载的python版本 检查新的python版本,你就可以开始了

获取python路径

ls /usr/bin/python*

然后设置你的python版本

alias python="/usr/bin/python3"

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

为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