好久不写博文了,本文没什么含金量,只是做一个记录。便于日后翻阅。
0.操作系统信息
[vagrant@localhost ~]$ cat /etc/issue
CentOS release 6.4 (Final)
Kernel \r on an \m
1.当前python版本信息
[vagrant@localhost bin]$ pwd
/usr/bin
[vagrant@localhost bin]$ ll -a python
-rwxr-xr-x. 2 root root 4864 2月 22 2013 python
[vagrant@localhost bin]$ python
Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
2.删掉当前python
[vagrant@localhost bin]$ sudo rm -rf python
3.下载且安装2.7.6安装包
[vagrant@localhost download]$ ll Python-2.7.6.tgz
-rw-r--r-- 1 vagrant vagrant 14725931 5月 14 2014 Python-2.7.6.tgz
[vagrant@localhost Python-2.7.6]$ ./configure && make && sudo make install
4.制作软连接把python2.7.6指向python
[vagrant@localhost bin]$ sudo ln -s /usr/local/bin/python2.7 python
[vagrant@localhost bin]$ pwd
/usr/bin
[vagrant@localhost bin]$ ll python
lrwxrwxrwx 1 root root 24 2月 14 14:29 python ->/usr/local/bin/python2.7
ok,现在的python环境切换成2.7.6了。
[vagrant@localhost ~]$ python
Python 2.7.6 (default, Feb 14 2015, 14:13:13)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
python是升级成功了,可是yum不能使用了。。。
[vagrant@localhost webservice]$ 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:
2.7.6 (default, Feb 14 2015, 14:13:13)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
找不到yum模块了
解决方法:
[vagrant@localhost webservice]$ vi /usr/bin/yum
编辑第一行
#!/usr/bin/python
import sys
try:
#!/usr/bin/python2.6
import sys
try:
[vagrant@localhost webservice]$ yum --version
3.2.29
Installed: rpm-4.8.0-32.el6.x86_64 at 2013-11-03 07:59
Built : CentOS BuildSystem <http://bugs.centos.org> at 2013-02-22 02:13
Committed: Florian Festi <ffesti@redhat.com> at 2012-11-15
Installed: yum-3.2.29-40.el6.centos.noarch at 2013-11-03 07:59
Built : CentOS BuildSystem <http://bugs.centos.org> at 2013-02-22 11:26
Committed: Johnny Hughes <johnny@centos.org> at 2013-02-21
Installed: yum-plugin-fastestmirror-1.1.30-14.el6.noarch at 2013-11-03 07:59
Built : CentOS BuildSystem <http://bugs.centos.org> at 2012-06-22 12:23
Committed: Zdenek Pavlas <zpavlas@redhat.com> at 2012-04-26
参考:http://see.sl088.com/wiki/Centos5_升级Python