Fork me on GitHub

Centos 6.4 python 2.6 升级到 2.7

眼看着python3 都出来了,vps上用的还是2.4的版本额,确实汗了一把。决定升级下python。
python2.7是2.X的最后一个版本,同时她也加入了一部分3.X的新特性。so 让我们升级吧!
查看系统当前python版本
  1. 2: [root@wangyuelou ~]# python
  2.    1:  
  3.    3: Python 2.4.3 (#1, May  5 2011, 16:39:10) 
  4.    4: [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
  5.    5: Type "help", "copyright", "credits" or "license" for more information.
  6.    6: >;>> 
  7.    7: [root@wangyuelou ~]# 
下载新版本的python
  1. 1: [root@wangyuelou ~]# wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tgz
解压缩 以及编译
  1.    1: [root@wangyuelou ~]# tar xvf Python-2.7.2.tar.tgz
  2.    2: [root@wangyuelou Python-2.7.2]# ./configure --prefix=/usr/local/python27
  3.    3: [root@wangyuelou Python-2.7.2]# make
  4.    4: [root@wangyuelou Python-2.7.2]# make install
  5.    5: [root@wangyuelou Python-2.7.2]# ls /usr/local/python27/ -al
  6.    6: total 28
  7.    7: drwxr-xr-x  6 root root 4096 Jul 14 00:21 .
  8.    8: drwxr-xr-x 20 root root 4096 Jul 14 00:17 ..
  9.    9: drwxr-xr-x  2 root root 4096 Jul 14 00:21 bin
  10.   10: drwxr-xr-x  3 root root 4096 Jul 14 00:21 include
  11.   11: drwxr-xr-x  4 root root 4096 Jul 14 00:21 lib
  12.   12: drwxr-xr-x  3 root root 4096 Jul 14 00:21 share
覆盖原来的python链接
  1.    1: [root@wangyuelou Python-2.7.2]# mv /usr/bin/python /usr/bin/python_old
  2.    2: [root@wangyuelou Python-2.7.2]# ln -s /usr/local/python27/bin/python /usr/bin/
  3.    3: [root@wangyuelou Python-2.7.2]# python
  4.    4: Python 2.7.2 (default, Jul 14 2011, 00:20:14) 
  5.    5: [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
  6.    6: Type "help", "copyright", "credits" or "license" for more information.
  7.    7: >>> 

此处已经可以正常使用python2.7了
但是因为yum是使用的2.4的版本来用的,所以 还需要修改一下
  1.    1: [root@wangyuelou ~]# yum 
  2.    2: There was a problem importing one of the Python modules
  3.    3: required to run yum. The error leading to this problem was:
  4.    4:  
  5.    5:    No module named yum
  6.    6:  
  7.    7: Please install a package which provides this module, or
  8.    8: verify that the module is installed correctly.
  9.    9:  
  10.   10: It's possible that the above module doesn't match the
  11.   11: current version of Python, which is:
  12.   12: 2.7.2 (default, Jul 14 2011, 00:20:14) 
  13.   13: [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)]
  14.   14:  
  15.   15: If you cannot solve this problem yourself, please go to 
  16.   16: the yum faq at:
  17.   17:   http://wiki.linux.duke.edu/YumFaq
  18.   18:   
  19.   19:  
编辑yum
  1. 20: [root@wangyuelou Python-2.7.2]# vim /usr/bin/yum  
  1. 22: #!/usr/bin/python   #修改此处为2.4的位置
在vim中的第一行将  #!/usr/bin/python 修改为 #!/usr/bin/python2.4
  1. 25: #!/usr/bin/python2.4
再次运行yum
  1. 26: [root@wangyuelou ~]# yum 
  2.   27: Loaded plugins: fastestmirror
  3.   28: You need to give some command
  4.   29: usage: yum [options] COMMAND
  5.   30:  
  6.   31: List of Commands:
  7.   32:  
  8.   33: check-update   Check for available package updates
  9.   34: clean          Remove cached data
  10.   35: deplist        List a package's dependencies
  11.   36: downgrade      downgrade a package
  12.   37: erase          Remove a package or packages from your system
  13.   38: groupinfo      Display details about a package group
  14.   39: groupinstall   Install the packages in a group on your system
  15.   40: grouplist      List available package groups
  16.   41: groupremove    Remove the packages in a group from your system
  17.   42: help           Display a helpful usage message
  18.   43: info           Display details about a package or group of packages
  19.   44: install        Install a package or packages on your system
  20.   45: list           List a package or groups of packages
  21.   46: localinstall   Install a local RPM

yum 又可以使用了





posted @ 2016-01-21 16:37  LookPHP  阅读(276)  评论(0编辑  收藏  举报