Ubuntu 16.04 安装python3

Ubuntu 16.04 安装python3

第一步: 换源

先备份

sudo cp /etc/apt/sources.list sources.list.bak 

换阿里源

sudo gedit /etc/apt/sources.list

将阿里源复制进去,保存

# 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
# 装不上, 一个一个来
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
# 执行安装前的配置(生成Makefile文件)
cd Python-3.7.4/
./configure --prefix=/usr/local/python37 --enable-optimizations
# 构建和安装
sudo make && make install
# 删除软连接,注册软链接
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

测试是否成功

(安装Python 3一定不能破坏系统原来的Python2,Python3)
python3 --version
python --version
pip3 --version

你可能感兴趣的:(Ubuntu 16.04 安装python3)