Linux  python2  3  共存

whereis python
ll python*

下载python3的包之前,要先安装相关的依赖包,用于下载编译python3:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

默认的centos7是没有安装pip,先添加epel扩展源
yum -y install epel-release

安装pip
yum install python-pip

用pip装wget
pip install wget


用wget下载python3的源码包,或者自己先下载好,上传到服务器再安装,如果网络快可以直接安装

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

编译python3源码包,解压

xz -d Python-3.6.8.tar.xz tar -xf Python-3.6.8.tar

cd Python-3.6.8

./configure prefix=/usr/local/python3

make && make install


安装依赖zlib、zlib-deve

yum install zlib zlib

yum install zlib zlib-devel


添加软链接,将原来的链接备份

mv /usr/bin/python /usr/bin/python.bak

cd /usr/local/bin/
python3 -> python3.6

默认2.7 python3 3.6