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

当前回答

将Ubuntu 18.04中的默认Python 3.6.8更改为Python 3.7。

安装Python 3.7

安装Python3.7并将其配置为默认解释器的步骤。

使用apt-get安装python3.7包 Sudo apt-get install python3.7 将Python3.6和Python 3.7添加到update-alternatives中

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2

更新Python 3以指向Python 3.7 Sudo update-alternatives——config python3 Python 3.7输入2 测试python版本

python3 --version
Python 3.7.1 

其他回答

这是一个简单的方法,适用于我。

sudo ln -s /usr/bin/python3 /usr/bin/python

您可以更改/usr/bin/python3作为python3的路径(或您想要的版本)。

但是请记住,update-alternatives可能是最好的选择。

获取python路径

ls /usr/bin/python*

然后设置你的python版本

alias python="/usr/bin/python3"
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版本,你就可以开始了

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

# 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中准备好。