• 学派吧-由新云网络独家赞助-https://www.sq9.cn。

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

unix admin 5年前 (2019-07-23) 2267次浏览 已收录 0个评论 扫描二维码
文章目录[隐藏]

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

问题:

$ 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

学派吧 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python升级带来的yum异常问题:File “/usr/bin/yum”, line 30
喜欢 (1)
[pay@sq9.cn]
分享 (0)
关于作者:
腾讯云-运维运维 QQ 690624
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址