1- 源码编译安装python2.7版本
1.1- 下载源码包
wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz
1.2- 安装依赖包
centos/redhat:
yum install -y gcc zlib zlib-devel openssl openssl-devel
ubuntu/debian:
apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat-dev
1.3- 解压源码包
tar -zxvf Python-2.7.14.tgz
1.4- 编译
cd Python-2.7.14
./configure --enable-optimizations --prefix=/usr/local/python2.7.14
vim Modules/Setup
默认这块是注释的,放开注释即可。这块功能是开启SSL模块,不然会出现安装完毕后,提示找不到ssl模块的错误。
修改后:
1.5- 安装
make && make install
ln -s /usr/local/python2.7.14/bin/python2.7 /usr/bin/python2.7.14
1.6- 检查版本
python2.7.14 --version
Python 2.7.14
2- 源码编译安装python3.7版本
2.1- 下载安装包
wget https://www.python.org/ftp/3.7.0/Python-3.7.0.tgz
2.2- 解压
tar -xvf Python-3.7.0.tgz
2.3- 安装依赖包
centos/redhat:
yum install -y gcc zlib zlib-devel openssl openssl-devel
ubuntu/debian:
apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat-dev
2.4- 编译
cd /Python3.7.0
./configure --prefix=/usr/local/python/python-3.7.0
2.5- 安装
make && make install
ln -s /usr/local/python/python-3.7.0/bin/python3.7 /usr/bin/python3.7
2.6- 检查版本
python3.7.0 --version
Python 3.7.0