python升级带来的yum异常问题:File “/usr/bin/yum”, line 30

今天给大家带来一个关于python的问题。

python升级带来的yum异常问题:File "/usr/bin/yum", line 30

问题:

$ yum

File “/usr/bin/yum”, line 30

except KeyboardInterrupt, e:

^

SyntaxError: invalid syntax

原因:

这是因为yum采用python作为命令解释器,这可以从/usr/bin/yum文件中第一行#!/usr/bin/python发现。而python版本之间兼容性不太好,使得2.X版本与3.0版本之间存在语法不一致问题。而CentOS 5自带的yum采用的是python2.4,当系统将python升级到2.6或3.0后,出现语法解释错误。

解决办法:

很简单,一是升级yum,一是修改yum的解释器为旧版本python2.4(如果你没有采用覆盖升级的话)。

升级yum的作法就不详述了。修改yum的解释器为旧版本python2.4:

$ vi /usr/bin/yum

将第一行”#!/usr/bin/python” 改为 “#!/usr/bin/python2.4″即可。
或者修改默认的python版本,/usr/bin/python为2.4.

[root@rhel6lhr Packages]# yum install  perl-IO-Socket-SSL
  File "/usr/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax
[root@rhel6lhr Packages]# python
Python 3.6.4 (default, Apr 15 2018, 10:55:33) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()
[root@rhel6lhr Packages]# 
[root@rhel6lhr Packages]# 
[root@rhel6lhr Packages]# 
[root@rhel6lhr Packages]# which python
/usr/bin/python
[root@rhel6lhr Packages]# python
python             python2.6          python3            python3.6-config   python3.6m-config  python_bk          
python2            python2_bk         python3.6          python3.6m         python3-config     
[root@rhel6lhr Packages]# ll /usr/bin/python
lrwxrwxrwx 1 root root 34 Apr 15  2018 /usr/bin/python -> /usr/bin/python3.6.4/bin/python3.6
[root@rhel6lhr Packages]# rm -rf /usr/bin/python
[root@rhel6lhr Packages]# ll /usr/bin/python    
ls: cannot access /usr/bin/python: No such file or directory
[root@rhel6lhr Packages]# ll /usr/bin/python3.6.4/bin/python3.6
-rwxr-xr-x 2 root root 10037966 Apr 15  2018 /usr/bin/python3.6.4/bin/python3.6
[root@rhel6lhr Packages]# python2
Python 2.6.6 (r266:84292, Sep  4 2013, 07:46:00) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> 
>>> exit()
[root@rhel6lhr Packages]# 
[root@rhel6lhr Packages]# 
[root@rhel6lhr Packages]#  ln -s /usr/bin/python2 /usr/bin/python

主题测试文章,只做测试使用。发布者:admin,转转请注明出处:https://www.xp8.net/server/3751.html

(0)
admin的头像admin
上一篇 2019年7月16日 上午12:44
下一篇 2019年7月23日 下午11:19

相关推荐

发表回复

登录后才能评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
学派网官网正在升级改造中,如有影响访问,敬请谅解