python2.7是2.X的最后一个版本,同时她也加入了一部分3.X的新特性。并且具有更好的性能,修改多个bug。所以决定升级到最新的2.7版,我的目前的版本是2.4.3
查看当前python版本
[root@pythontab.com ~]# pythonPython 2.4.3 (#1, Sep 3 2009, 15:37:37) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>>
下载新版本的python
[root@pythontab.com ~]# wget http://python.org/ftp/python/2.7.8/Python-2.7.8.tgz
解压缩 以及编译
[root@pythontab.com ~]# tar xvf Python-2.7.8.tar.bz2 [root@pythontab.com Python-2.7.8]# ./configure --prefix=/usr/local/python27[root@pythontab.com Python-2.7.8]# make[root@pythontab.com Python-2.7.8]# make install
最新2.7.8版本的python已经安装到了系统中,但是还没有完成
再次查看python版本,发现依然是2.4.3版本
[root@pythontab.com ~]# pythonPython 2.4.3 (#1, Sep 3 2009, 15:37:37) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>>
下面我们来解决这个问题
把原来的python重命名成python_old,注意不要删除它,还有用,下面会说到
[root@pythontab.com Python-2.7.8]# mv /usr/bin/python /usr/bin/python_old
建立新的python的软链接
[root@pythontab.com Python-2.7.8]# ln -s /usr/local/python27/bin/python /usr/bin/
这时候我们再查看一下版本,发现正常啦!
[root@pythontab.com Python-2.7.8]# pythonPython 2.7.8 (default, Dec 3 2014, 10:51:34) [GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>>
至此我们已经可以正常使用python2.7
但是我们还有最后一个问题要解决
但是因为yum是使用的python2.4的版本,所以 还需要修改一下(前面我们重命名的python_old现在派上用场啦)
[root@pythontab.com ~]# yum There was a problem importing one of the Python modulesrequired to run yum. The error leading to this problem was:No module named yumPlease install a package which provides this module, orverify that the module is installed correctly.It's possible that the above module doesn't match thecurrent version of Python, which is:Python 2.7.8 (default, Dec 3 2014, 10:51:34) [GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2If you cannot solve this problem yourself, please go to the yum faq at:http://wiki.linux.duke.edu/YumFaq
[root@pythontab.com Python-2.7.8]# vim /usr/bin/yum #!/usr/bin/python #修改此处为2.4的位置[root@pythontab.com ~]# vim /usr/bin/yum #!/usr/bin/python2.4[root@pythontab.com ~]# yum Loaded plugins: fastestmirrorYou need to give some commandusage: yum [options] COMMANDList of Commands:check-update Check for available package updatesclean Remove cached datadeplist List a package's dependenciesdowngrade downgrade a packageerase Remove a package or packages from your systemgroupinfo Display details about a package groupgroupinstall Install the packages in a group on your systemgrouplist List available package groupsgroupremove Remove the packages in a group from your systemhelp Display a helpful usage messageinfo Display details about a package or group of packagesinstall Install a package or packages on your systemlist List a package or groups of packageslocalinstall Install a local RPM
yum 又可以使用了
至此python升级大功告成!