1. 程式人生 > >ubuntu 16.04 安裝 python3.6

ubuntu 16.04 安裝 python3.6

ubuntu

檢查已安裝的 python 版本

在 terminal 中

python -V
顯示 Python 2.7.12

python3 -V
顯示 Python 3.5.2

安裝依賴(可選)

若跳過這一步,可能在使用 python3.6 解釋器的 virtualenv 中, pip 安裝第三方包失敗。
通過 apt-get 安裝依賴

sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

下載 python 3.6 源代碼

前往 python 官網,進入下載頁面 —— 源代碼, 點擊最新的 python 版本。(此時為 3.6.5)
技術分享圖片
在新打開的頁面最底部,右鍵第一項 Gzipped source tarball ,復制鏈接地址。
技術分享圖片
打開 terminal , 切換到 opt 目錄,用 wget 下載剛復制的鏈接。
cd /opt
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
解壓
tar -xvf Python-3.6.5.tgz
會解壓到名為 Python-3.6.5 的文件夾。

安裝 python 3.6

切換到解壓出來的 Python-3.6.5 目錄,然後依次執行命令進行安裝。(可能需要 sudo)

cd /opt/Python-3.5.6
./configure
make
sudo make install

python 3.6 的解釋器會安裝在 /usr/local/bin/python3.6 。安裝完成後 python3 命令會指向 python 3.6 解釋器,如下列命令所示。

python3.6 -V
顯示 Python 3.6.5

python3 -V
顯示 Python 3.6.5

python3.5 版本可用 python3.5 調用

python3.5 -V
顯示 Python 3.5.2

ubuntu 16.04 安裝 python3.6