CentOS7并存安装Python3和Pip3

1、安装Python3和Pip3依赖包
yum -y install gcc gcc-c++ openssl-devel libffi-devel zlib-devel bzip2-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel

2、下载安装Python3和Pip3
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar -zxf Python-3.7.0.tgz
cd Python-3.7.0
vi Modules/Setup.dist

# 去掉以下行的注释,启用ssl支持
_socket socketmodule.c timemodule.c

SSL=/usr/local/ssl
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto

./configure --prefix=/usr/local/python3 --enable-optimizations
make && sudo make install

3、添加运行文件到PATH
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

4、添加国内pypi镜像
mkdir ~/.pip
vi ~/.pip/pip.conf

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

5、升级pip3到最新版本
pip3 install --upgrade pip

你可能感兴趣的:(CentOS7并存安装Python3和Pip3)