查看 python 的版本
下载并安装 Python-2.7.5
建立软连接,使系统默认的 python 指向 python2.7
正常情况下,即使 python2.7 安装成功后,系统默认指向的 python 仍然是 2.4.3 版本,考虑到 CentOS5.6 系统中的 yum 是基于 python2.4 才能正常工作,所以不要卸载 python2.4 版本。 那么 如何 实现将系统默认的 python 指向到 2.7 版本呢?
未做修改前:
做如下修改:
上面的 3 步分别为:
1.删除之前的软连接;
2.将默认 python 重命名为 python2.4 以给 yum 使用(这里可以省略该步骤,因为 python2.4 本身就存在);
3.将默认 python 软连接到 python2.7 上。
检验 python 指向是否成功
解决默认 python 软链接指向 python2.7 版本后 yum 不能正常工作的问题
将文件头部的
改成
整个升级过程完成,可以使用 Python2.7.5 版本了。
============== 我是分割线 =============
当默认 python 升级到 2.7.5 后,在未修改 /usr/bin/yum 时,运行 yum 相关命令会得到如下错误:
这是因为 yum 对 python 版本具有依赖性的原因。/usr/bin/yum 的内容如下:
1 | [root@localhost ~] # python -V |
2 | Python 2.4.3 |
下载并安装 Python-2.7.5
1 | [root@localhost ~] # wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2 |
2 | [root@localhost ~] # tar -jxvf Python-2.7.5.tar.bz2 |
3 | [root@localhost ~] # cd Python-2.7.5 |
4 | [root@localhost Python-2.7.5] # ./configure |
5 | [root@localhost Python-2.7.5] # make |
6 | [root@localhost Python-2.7.5] # make install |
建立软连接,使系统默认的 python 指向 python2.7
正常情况下,即使 python2.7 安装成功后,系统默认指向的 python 仍然是 2.4.3 版本,考虑到 CentOS5.6 系统中的 yum 是基于 python2.4 才能正常工作,所以不要卸载 python2.4 版本。 那么 如何 实现将系统默认的 python 指向到 2.7 版本呢?
未做修改前:
1 | [root@localhost Python-2.7.5] # ll /usr/bin/python* |
2 | -rwxr-xr-x 2 root root 8304 Mar 6 2011 /usr/bin/python |
3 | lrwxrwxrwx 1 root root 6 Jul 4 2013 /usr/bin/python2 -> python |
4 | -rwxr-xr-x 2 root root 8304 Mar 6 2011 /usr/bin/python2.4 |
1 | [root@localhost Python-2.7.5] # rm -f /usr/bin/python2 |
2 | [root@localhost Python-2.7.5] # mv /usr/bin/python /usr/bin/python2.4 |
3 | [root@localhost Python-2.7.5] # ln -s /usr/local/bin/python2.7 /usr/bin/python |
1.删除之前的软连接;
2.将默认 python 重命名为 python2.4 以给 yum 使用(这里可以省略该步骤,因为 python2.4 本身就存在);
3.将默认 python 软连接到 python2.7 上。
检验 python 指向是否成功
1 | [root@localhost Python-2.7.5] # python -V |
2 | Python 2.7.5 |
解决默认 python 软链接指向 python2.7 版本后 yum 不能正常工作的问题
1 | [root@localhost Python-2.7.5] # vi /usr/bin/yum |
2 |
3 | #!/usr/bin/python |
4 | ... |
1 | #!/usr/bin/python |
1 | #!/usr/bin/python2.4 |
============== 我是分割线 =============
当默认 python 升级到 2.7.5 后,在未修改 /usr/bin/yum 时,运行 yum 相关命令会得到如下错误:
01 | [root@localhost Python-2.7.5] # yum list |
02 | There was a problem importing one of the Python modules |
03 | required to run yum. The error leading to this problem was: |
04 |
05 | No module named yum |
06 |
07 | Please install a package which provides this module, or |
08 | verify that the module is installed correctly. |
09 |
10 | It 's possible that the above module doesn' t match the |
11 | current version of Python, which is: |
12 | 2.7.5 (default, Jul 5 2013, 02:21:36) |
13 | [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] |
14 |
15 | If you cannot solve this problem yourself, please go to |
16 | the yum faq at: |
17 | http://wiki.linux.duke.edu/YumFaq |
18 | |
19 |
20 | [root@localhost Python-2.7.5] # |
01 | [root@localhost Python-2.7.5] # vi /usr/bin/yum |
02 |
03 | #!/usr/bin/python |
04 | import sys |
05 | try: |
06 | import yum |
07 | except ImportError: |
08 | print >> sys.stderr, "" "\ |
09 | There was a problem importing one of the Python modules |
10 | required to run yum. The error leading to this problem was: |
11 |
12 | %s |
13 |
14 | Please install a package which provides this module, or |
15 | verify that the module is installed correctly. |
16 |
17 | It 's possible that the above module doesn' t match the |
18 | current version of Python, which is: |
19 | %s |
20 |
21 | If you cannot solve this problem yourself, please go to |
22 | the yum faq at: |
23 | http://wiki.linux.duke.edu/YumFaq |
24 |
25 | "" " % (sys.exc_value, sys.version) |
26 | sys. exit (1) |
27 |
28 | sys.path.insert(0, '/usr/share/yum-cli' ) |
29 | try: |
30 | import yummain |
31 | yummain.user_main(sys.argv[1:], exit_code=True) |
32 | except KeyboardInterrupt, e: |
33 | print >> sys.stderr, "\n\nExiting on user cancel." |
34 | sys. exit (1) |
35 | ~ |