ubuntu 16.04 安装 python3.6
2018-05-01 本文已影响2161人
jiang
检查已安装的 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