Linux 上如何安裝並切換最新版本的 Python 3.6

Shekin發表於2017-07-05

Linux 上如何安裝並切換最新版本的 Python 3.6

Python 是 Linux 中一種最流行的程式語言。它被寫成了各種工具和庫。除此之外,Python 在開發者之間很流行因為它非常簡單,並且實際很容易掌握。如果你安裝了 Linux 系統,正在學習 Python 並想要使用最新的版本的話,那麼這篇文章就是為你而寫的。現在我已經安裝好了 Linux Mint 18。預設安裝的版本是 2.7 和 3.5。你可以用這個命令檢查:

$ python -V
$ python2 -V
$ python3 -V

安裝最新的 Python 3.6 到 Linux 中:

$ sudo add-apt-repository ppa:jonathonf/python-3.6
$ sudo apt update
$ sudo apt install python3.6

檢查已安裝的 Python 3.6 版本

$ python3.6 -V

請注意舊版本仍然還在,它仍然可以透過 python3 可用,新的版本可以透過命令 python3.6。如果你想要預設使用這個版本而不是 3.5 執行所有的程式,這有個工具叫 update-alternatives。但是如果你嘗試獲取可能的列表,我們會得到錯誤:

Python 3.6  - install latest version into Linux Mint

這是正常的,你首先需要為那個問題設定檔案,因為維護者沒有設定這個:

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

現在再次檢視:

$ update-alternatives --list python3

Python 3.6  - install latest version into Linux Mint

現在我們選擇需要的版本並按需切換。對於設定使用配置命令:

$ sudo update-alternatives --config python3

Python 3.6  - install latest version into Linux Mint

在提示符中,你需要指定預設使用的編號。

選擇版本時要小心,不要去動 python(python2),只使用我說的 python3,Python 2.7 編寫了各種系統工具,如果你嘗試用錯誤的直譯器版本執行它們,可能就不會工作。

願原力與你同在,好運!!!


via: https://mintguide.org/other/794-python-3-6-install-latest-version-into-linux-mint.html

作者: Shekin 譯者:geekpi 校對:wxy

本文由 LCTT 原創編譯,Linux中國 榮譽推出

相關文章