1.环境准备

yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ automake autoconf libtool make wget

yum install -y openssl net-tools bash-completion openssh-server openssh-clients lrzsz vim unzip zip iperf iperf3 iftop wget curl openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ automake autoconf libtool make bash-completion udns-devel vim wget telnet-server telnet.* net-tools ntpdate nc

2.首先去官网下载python3.6

https://www.python.org/ftp/python/

创建python3.6目录

mkdir /usr/local/python2.7
cd /usr/local/python2.7

mkdir /usr/local/python3.6
cd /usr/local/python3.6

mkdir /usr/local/python3.8
cd /usr/local/python3.8

3.这里我们下载

yum -y install wget  # 安装wget
wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz

wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz

wget https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tgz

4.解压python3.6安装包

tar -xzvf Python-2.7.5.tgz

tar -xzvf Python-3.6.8.tgz

tar -xzvf Python-3.8.8.tgz

5.进入解压路径

cd Python-2.7.5

cd Python-3.6.8

cd Python-3.8.8

6.源码安装三个步骤

# 配置(configure)
./configure --prefix=/usr/local/python2.7

./configure --prefix=/usr/local/python3.6

./configure --prefix=/usr/local/python3.8

# 编译(make)
make

# 安装(make install)
make altinstall
./configure --prefix=/usr/local/python2.7 && make && make install

./configure --prefix=/usr/local/python3.6 && make && make install

./configure --prefix=/usr/local/python3.8 && make && make install

7.建立软连接

ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python2.7

ln -s /usr/local/python3.6/bin/python3.6 /usr/bin/python3.6
ln -s /usr/local/python3.6/bin/pip3.6 /usr/bin/pip3.6


ln -s /usr/local/python3.8/bin/python3.8 /usr/bin/python3.8
ln -s /usr/local/python3.8/bin/pip3.8 /usr/bin/pip3.8

8.pip安装

https://pypi.python.org/pypi/setuptools

https://pypi.python.org/packages/ff/d4/209f4939c49e31f5524fa0027bf1c8ec3107abaf7c61fdaad704a648c281/setuptools-21.0.0.tar.gz#md5=81964fdb89534118707742e6d1a1ddb4 # 下载地址

tar vxf setuptools-21.0.0.tar.gz 
cd setuptools-21.0.0
python setup.py  install


https://pypi.python.org/pypi/pip
https://pypi.python.org/packages/41/27/9a8d24e1b55bd8c85e4d022da2922cb206f183e2d18fee4e320c9547e751/pip-8.1.1.tar.gz#md5=6b86f11841e89c8241d689956ba99ed7   # 下载地址

tar vxf pip-8.1.1.tar.gz 
cd pip-8.1.1
python setup.py install


ln -s /usr/local/python2.7/bin/pip2.7 /usr/bin/pip2.7

9.加入环境变量

在vim /etc/profile最后一行中加入变量

export PYTHON_HOME=/usr/local/python2.7
export PATH=$PYTHON_HOME/bin:$PATH
export PYTHONDONTWRITEBYTECODE=1  #设置不生成字节码文件

export PYTHON_HOME=/usr/local/python3.6
export PATH=$PYTHON_HOME/bin:$PATH
export PYTHONDONTWRITEBYTECODE=1  #设置不生成字节码文件

export PYTHON_HOME=/usr/local/python3.8
export PATH=$PYTHON_HOME/bin:$PATH
export PYTHONDONTWRITEBYTECODE=1  #设置不生成字节码文件

# 使环境变量生效
source /etc/profile

sed -i '$a\export PYTHON_HOME=/usr/local/python3.8' /etc/profile
sed -i '$a\export PATH=$PYTHON_HOME/bin:$PATH' /etc/profile
sed -i '$a\export PYTHONDONTWRITEBYTECODE=1' /etc/profile && source /etc/profile
cat /etc/profile

10.检测是否安装成功

python2.7   # 进入python2.7
pip2.7 -V    # 显示pip的版本

python3.6    # 进入python3.6
pip3.6 -V    # 显示pip的版本

python3.8    # 进入python3.6
pip3.8 -V    # 显示pip的版本