python2--升级python3
先安装开发工具包:
yum -y group install "Development Tools"
安装Python的依赖包:
yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel vim
下载最新的Python包:
wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tgz
或者这里下载后上传:https://www.python.org/downloads/source/
解压编译安装:
tar xf Python-3.5.3.tgz
cd Python-3.5.3
./configure --prefix=/usr/local/python3.5
make
make altinstall(这一步如果是Python3.7会报错,需要另外安装一个依赖包)
为pip3和Python3创建链接:
[root@CentOS Python-3.5.3]# ln -fs /usr/local/python3.5/bin/python3 /usr/local/bin/
[root@CentOS Python-3.5.3]# ln -fs /usr/local/python3.5/bin/pip3 /usr/local/bin/
[root@CentOS Python-3.5.3]# mv /usr/bin/python/usr/bin/python_old
[root@CentOS Python-3.5.3]# ln -fs /usr/local/python3.5/bin/python3.5 /usr/bin/python
[root@CentOS Python-3.5.3]# ln -fs /usr/local/python3.5/bin/pip3.5 /usr/bin/pip
验证安装:
pip -V
python -V
修改yum文件
vim /usr/bin/yum
将 #!/usr/bin/python 修改为 #!/usr/bin/python2.7
详情参考:https://www.cnblogs.com/youngthink/p/6668127.html