经常遇到一些python模块没有包含相应属性,此时可能是python版本问题。


1.首先查看原python版本

[root@python ~]# python -V

Python 2.6.6


2.下载python-2.7.12版本,解压并安装

[root@python ~]# wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz

[root@python ~]# tar -zxvf Python-2.7.12.tgz 

[root@python ~]# cd Python-2.7.12

[root@python Python-2.7.12]# ./configure --prefix=/usr/local/python2.7

[root@python Python-2.7.12]#make && make install


3.查看新版本信息

[root@python ~]# /usr/local/python2.7/bin/python2.7 -V

Python 2.7.12


4.建立软连接,使系统默认的 python指向 python2.7

[root@python ~]# mv /usr/bin/python /usr/bin/python2.6.6 

[root@python ~]# ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python 


5.重新检查Python版本

[root@python ~]# python -V

Python 2.7.12


!!!注意,因为yum是不兼容python2.7版以后本,所以需要指定 yum 的Python版本

[root@python ~]# vim /usr/bin/yum 

#!/usr/bin/python

改为

#!/usr/bin/python2.6.6


ending!!!!升级成功