Ubuntu18.04 Python 升级至3.8.2

在 Ubuntu 18.04 中,python3 的默认版本为 3.6

通过Apt安装(使用 deadsnakes PPA 库安装)

  1. 安装依赖包
$ sudo apt update
$ sudo apt install software-properties-common
  1. 添加 deadsnakes PPA 源
$ sudo add-apt-repository ppa:deadsnakes/ppa
  1. 安装 python 3.8
$ sudo apt install python3.8
$ python3.8 -V
Python 3.8.2

配置Python3.8为系统默认Python3

  1. 将 python 各版本添加到 update-alternatives
$ which python3.8
/usr/bin/python3.8
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
$ which python3.5
/usr/bin/python3.5
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
  1. 配置 python3 默认指向 python3.8
$ sudo update-alternatives --config python3

There are 2 choices for the alternative python3 (providing /usr/bin/python3).
  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.5   2         auto mode
  1            /usr/bin/python3.5   2         manual mode
  2            /usr/bin/python3.8   1         manual mode
  
Press <enter> to keep the current choice[*], or type selection number: 2
  1. 测试 python 版本
$ python3 -V

Python 3.8.2

你可能感兴趣的:(linux操作系统)