1 安装python3
Centos自带python2,由于执行yum需要python2,所以即使安装了python3也不能删除python2
1.安装依赖包
# yum -y groupinstall "Development tools"
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
3.7版本需要一个新的包libffi-devel,安装此包之后再次进行编译安装即可。
# yum install libffi-devel -y
2.软件下载
下载自己需要的python版本,例如python3.6.2,下载要花费一段时间,要耐心等待
# mkdir /usr/local/python3 -p
# cd /usr/loacl/python3/
# wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
# mv Python-3.6.2.tar.xz /usr/local/python3
# tar -xf Python-3.6.2.tar.xz
# cd Python-3.6.2
# ./configure --prefix=/usr/local/python3
# make && make install
3.创建软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
4.修改配置文件
修改yum配置文件,python2与python3共存
//把#!/usr/bin/python修改为#!/usr/bin/python2(配置文件第一行)
vi /usr/bin/yum
//把文件里面的#!/usr/bin/python 也修改为#!/usr/bin/python2
此时完成python3安装,且实现与python2共存,保持yum命令可用
vi /usr/libexec/urlgrabber-ext-down