在 Ubuntu 18.04 /centos7上安装 Python 3.7

扩展源安装

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa

# 按回车继续
sudo apt install python3.7
python3.7 --version
#安装pip
wget https://bootstrap.pypa.io/get-pip.py
python3.7 get-pip.py
#安装python3.7-develop 包
sudo apt install python3.7-dev

源码安装

sudo apt updatesudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
tar -xf Python-3.7.3.tar.xz
cd Python-3.7.3
#配置
./configure --enable-optimizations
#编译 使用8个cpu同时编译
make -j 8
#安装python3.7
sudo make altinstall
#测试
python3.7 --version
#安装pip
wget https://bootstrap.pypa.io/get-pip.py
python3.7 get-pip.py
#安装python3.7-develop 包
sudo apt install python3.7-dev

centos7

#源码安装
1. 先安装依赖
yum groupinstall "Development Tools" -y
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel libpcap-devel xz-devel libffi-deve -y
2.下载源码包
https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz
tar -xvf Python-3.7.4.tar.xz
cd Python-3.7.4
#配置
./configure --prefix=/usr/local/python3
#可选开启 优化
./configure --enable-optimizations
#编译 (-j 8 代表开启8核同时编译)
make -j 8 
#安装
make install

你可能感兴趣的:(在 Ubuntu 18.04 /centos7上安装 Python 3.7)