报错类型

(base) [root@localhost rstudio]# yum install shiny-server-1.5.9.923-x86_64.rpm 
  File "/usr/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax

原因分析

因为yum默认支持的是python2,当你升级为python3时,报错了。
如果你可以通过建入python2进入python2

(base) [root@localhost rstudio]# python2
Python 2.7.5 (default, Jul 13 2018, 13:06:57) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

那么可以修改yum的代码python改为python进行实现。

问题解决

vi /usr/bin/yum

将第一行的#!/usr/bin/python改为#!/usr/bin/python2即可。

#!/usr/bin/python2
import sys
try:
    import yum
except ImportError:
    print >> sys.stderr, """\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

问题解决。

后记

发现yum无论安装什么软件,都是报错,类型如下:

base) [root@localhost ~]# yum install yum-fastestmirror
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirror.jdcloud.com
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax

解决方法

  • 1, 进入编辑urlgrabber-ext-down
  • 2, 将python变为python2
#vi /usr/libexec/urlgrabber-ext-down

#!/usr/bin/python >--替换成-->#!/usr/bin/python2

搞定。