1. 概述
本文記錄在 Ubuntu 16.04 上將 python 升級為 3.8 版本,并配置為系統默認 python3 的過程。
在 Ubuntu 16.04 中,python3 的默認版本為 3.5:
$ python3 -V
Python 3.5.2
本文以在 Ubuntu 16.04 中安裝為例,方法同樣適用于 Ubuntu 18.04 。
2. 通過 Apt 安裝
Ubuntu 官方 apt 庫中還未收錄 python 3.8,這里使用 deadsnakes PPA 庫安裝。
2.1. 安裝依賴包
$ sudo apt update
$ sudo apt install software-properties-common
2.2. 添加 deadsnakes PPA 源
$ sudo add-apt-repository ppa:deadsnakes/ppa
Press [ENTER] to continue or Ctrl-c to cancel adding it.
2.3. 安裝 python 3.8
$ sudo apt install python3.8
$ python3.8 -V
Python 3.8.2
3. 配置 python3.8 為系統默認 python3
3.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.5 2
3.2. 配置 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 to keep the current choice[*], or type selection number: 2
選擇/輸入 2, 回車。
3.3 測試 python 版本
$ python3 -V
Python 3.8.2
資源
總結
到此這篇關于將 Ubuntu 16 和 18 上的 python 升級到最新 python3.8 的方法教程的文章就介紹到這了,更多相關 Ubuntu 16 和 18 升級到python 3.8 內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!