升级 Ubuntu上的 python版本
1. 不要卸载Ubuntu自带的Python2.7和Python3.5,直接安装新版本的Python,然后修改默认的Python软链接即可。
2.安装Python3.8
$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
Press Enter to continue
$ sudo apt install python3.8
报错:
E: Unable to locate package python3.8
E: Couldn't find any package by glob 'python3.8'
E: Couldn't find any package by regex 'python3.8'
解决方法:
$ sudo apt-get update
$ sudo apt install python3.8 //成功安装
$ python3.8 –version
Python 3.8.9
3.采用update-alternatives 切换版本
sudo update-alternatives –install /usr/bin/python python /usr/bin/python2.7 2
sudo update-alternatives –install /usr/bin/python python /usr/bin/python3.5 1
sudo update-alternatives –install /usr/bin/python python /usr/bin/python3.8 3
There are 3 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.8 3 auto mode
1 /usr/bin/python2.7 2 manual mode
* 2 /usr/bin/python3.5 1 manual mode
3 /usr/bin/python3.8 3 manual mode
Press <enter> to keep the current choice[*], or type selection number: 3
来源:一棵树是码农