python2.7是2.X的最後一個版本,同時她也加入了一部分3.X的新特性。並且具有更好的效能,修改多個bug。所以決定升級到最新的2.7版,我的目前的版本是2.4.3
檢視當前python版本
[root@pythontab.com ~]# python Python 2.4.3 (#1, Sep 3 2009, 15:37:37) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
1.最新版本python下載安裝
下載新版本的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 ~]# python Python 2.4.3 (#1, Sep 3 2009, 15:37:37) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
2. python多版本共存解決
下面我們來解決這個問題
把原來的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]# python Python 2.7.8 (default, Dec 3 2014, 10:51:34) [GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
至此我們已經可以正常使用python2.7
3.解決yum的python版本問題
但是我們還有最後一個問題要解決
但是因為yum是使用的python2.4的版本,所以 還需要修改一下(前面我們重新命名的python_old現在派上用場啦)
[root@pythontab.com ~]# yum There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: No module named yum Please install a package which provides this module, or verify that the module is installed correctly. It's possible that the above module doesn't match the current 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 linux2 If 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: fastestmirror You need to give some command usage: yum [options] COMMAND List of Commands: check-update Check for available package updates clean Remove cached data deplist List a package's dependencies downgrade downgrade a package erase Remove a package or packages from your system groupinfo Display details about a package group groupinstall Install the packages in a group on your system grouplist List available package groups groupremove Remove the packages in a group from your system help Display a helpful usage message info Display details about a package or group of packages install Install a package or packages on your system list List a package or groups of packages localinstall Install a local RPM
yum 又可以使用了
至此python升級大功告成!