1.先安装py3所依赖的软件包,否则可能会出现py3安装成功,却缺少相应的pip,命令:
yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
2.wegt下载python3源码并解压,版本可选择,命令:
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
tar -zxvf Python-3.6.4.tgz
3.进入解压出的文件夹,执行自检脚本设置并生成makefile文件,--prefix设置安装路径,命令:
cd Python-3.6.4
./configure --prefix=/usr/local/python3.6
4.make命令编译以及链接文件,然后使用make install命令安装,命令:
make
make install
5.使/usr/bin中指向python2的名为python的软连接改名成python2,pip改成pip2,命令:
cd /usr/bin
mv python python2
mv pip pip2
6./usr/bin中创建软连接,指向刚安装的python3,命令:
ln -s /usr/local/python3.6/bin/python3.6 /usr/bin/python
ln -s /usr/local/python3.6/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3.6/bin/pip3.6 /usr/bin/pip3
7.执行yum需要python2版本,修改yum的配置,命令:
vi /usr/bin/yum
#! /usr/bin/python 修改为 #! /usr/bin/python2
8.查看是否安装成功,命令:
python -V
python2 -V
python3 -V
pip2将会给python2下载模块,使用pip3会给python3下载模块