今天给大家带来一个关于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

阿里云CentOS/Windows服务器运维指南 | 阿里云腾讯云优惠活动 | 数据库优化教程-学派网









































评论前必须登录!
注册