Ubuntu 16.04 安裝python3
第一步: 換源
先備份
sudo cp /etc/apt/sources.list sources.list.bak
換阿里源
sudo gedit /etc/apt/sources.list
將阿里源復(fù)制進(jìn)去,保存
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
更新源
sudo apt-get update
sudo apt-get upgrade
安裝依賴
sudo apt-get dist-upgrade
# 全部依賴:
sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev
libreadline-dev tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat1-dev
liblzma-dev libffi-dev libc6-dev libffi-dev build-essential openssl
# 裝不上, 一個(gè)一個(gè)來
sudo apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
sudo apt-get install libssl-dev openssl
sudo apt-get install libffi-dev
sudo apt-get install libbz2-dev
安裝python3
# 解壓縮
tar zxvf Python-3.7.4
# 執(zhí)行安裝前的配置(生成Makefile文件)
cd Python-3.7.4/
./configure --prefix=/usr/local/python37 --enable-optimizations
# 構(gòu)建和安裝
sudo make && make install
# 刪除軟連接,注冊(cè)軟鏈接
rm -rf /usr/bin/python3
rm -rf /usr/bin/pip3
ln -s /usr/local/python37/bin/python3 /usr/bin/python3
# ln -s /usr/local/python37/bin/pip3.7 /usr/bin/pip3
sudo apt install python3-pip
測(cè)試是否成功
(安裝Python 3一定不能破壞系統(tǒng)原來的Python2,Python3)
python3 --version
python --version
pip3 --version