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

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

(0)
打赏 微信扫一扫 微信扫一扫
云大使的头像云大使
上一篇 2019年7月16日 上午12:44
下一篇 2019年7月23日 下午11:19

相关推荐

  • win2008 WEB环境配置之MYSQL5.6.22安装版安装配置方法教程-学派吧

    这篇文章主要介绍了win2008 R2 WEB环境配置之MYSQL 5.6.22安装版安装配置方法,需要的朋友可以参考下 版本选择 因为MySql的版本越来越多,而作为中小网站者可能没有足够的经济去购买商业版本,所以一般选择免费版,而且功能也是足够使用的。 有钱任性就下载企业版,哈哈。 目前使用最多的版本是mysql installer community,…

    服务器运维 2018年12月10日
    3.1K00
  • 宝塔bt设置ssl以后,bt宝塔后台无法打开的解决方法-学派吧

    宝塔面板是一款不错的控制面板,功能包括一键创建网站、FTP、数据库、SSL;安全管理,计划任务,文件管理,PHP多版本共存及切换;自带LNMP与LAMP不小心在宝塔面板设置里打开了ssl面板,现在无法打开宝塔面板,显示的是The client sent a plain HTTP request, but this server only speaks HTT…

    2019年5月5日
    6.4K00
  • centos(apache)压力并发测试安装及教程

    简介 Apache Benchmark(简称ab) 是Apache安装包中自带的压力测试工具 ,简单易用 在此提供 ab 在 centOS7 下的安装和使用方法 ①.ab(apache benchmark)安装 命令: yum -y install httpd-tools ab的使用 模拟并发请求100次,总共请求10000次 命令模板: ab -c 100…

    2019年3月13日
    2.9K00
  • 分享Linux/centos下如何查看环境变量-学派吧

    本篇文章主要给大家介绍linux下查看环境变量的命令方法,希望对需要的朋友有所帮助! 环境变量的查看 1.使用echo命令查看单个环境变量。例如: echo $PATH 2.使用env查看所有环境变量。例如: env 3.使用set查看所有本地定义的环境变量。 常用的环境变量: PATH 决定了shell将到哪些目录中寻找命令或程序 HOME 当前用户主目录…

    服务器运维 2019年5月7日
    4.9K00
  • 阿里云腾讯云安装管理面板centos宝塔面板安装教程

    2分钟装好面板,一键管理服务器Linux版请确保纯净系统安装(支持CentOS、Ubuntu、Debian、Fedora、Deepin),Web端管理,QQ群及论坛技术支持一键LAMP/LNMP、创建网站FTP、数据库、SSL;安全管理,计划任务,文件管理,PHP多版本共存及切换,一键开启Tomcat环境 Linux面板安装脚本 系统兼容性排序: Debia…

    2018年7月12日
    8.8K00

发表回复

登录后才能评论
联系我们

联系我们

18838889666

在线咨询: QQ交谈

邮件:xinyun@88.com

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

添加微信
添加微信
分享本页
返回顶部
---------官方优惠叠加渠道折扣:通过我们购买腾讯云/阿里云,价格更低,服务更优。更有专业配置指导与服务。微信同步:18838889666----