Linux Server yum 不可用,无法使用yum安装软件

因安装高版本python3.7后,造成 RedHat yum 不可用,无法使用yum 安装软件,随笔记录!


错误表现形式:

# 错误表现形式:
[root@localhost ~]# yum
  File "/usr/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax
[root@localhost ~]#

 

解决办法:

一、升级或卸载Python导致:

1、查看已安装python的版本,可能是当前系统存在多个python导致

查询已安装python

# 查询系统版本
[root@localhost ~]# cat /etc/os-release
NAME="Red Hat Enterprise Linux Server"               # Red Hat 7.5
VERSION="7.5 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="7.5"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.5 (Maipo)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.5:GA:server"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.5
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="7.5"
[root@localhost ~]# 

1.2 查询python版本

[root@localhost ~]# whereis python3
python3: /usr/bin/python3 /usr/local/python3
[root@localhost ~]#


[root@localhost ~]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz
[root@localhost ~]#


[root@localhost ~]# whereis python2
python2: /usr/bin/python2 /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /usr/include/python2.7 /usr/share/man/man1/python2.1.gz

1.3查询 python 软连接 

 [root@localhost ~]# ls -l /usr/bin/python*
lrwxrwxrwx. 1 root root   32 Sep 22 04:14 /usr/bin/python -> /usr/local/python3/bin/python3.7
lrwxrwxrwx. 1 root root    9 Sep 21 12:10 /usr/bin/python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 Feb 20  2018 /usr/bin/python2.7
lrwxrwxrwx. 1 root root   32 Sep 22 04:13 /usr/bin/python3 -> /usr/local/python3/bin/python3.7
[root@localhost ~]#

 1.4 默认路径是/usr/local/bin/python2.7,yum 可用:

为python2.7 创建一个/usr/bin/python软链接或者修改yum 的文件头

 为RedHat 默认 python2.7 创建一个软连接  /usr/bin/python 即可

# rm -rf  /usr/bin/python

# ln -s  /usr/local/bin/python2.7  /usr/bin/python

或者
根据1.3 python2.7 的软连接是 /usr/binpython2,修改 yum 文件

将 #!/usr/bin/python   修改为 #!/usr/bin/python2 即可

# 修改前:
[root@localhost ~]# cat /usr/bin/yum
#!/usr/bin/python                 
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:

   %s

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
%s

If you cannot solve this problem yourself, please go to
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

""" % (sys.exc_value, sys.version)
    sys.exit(1)

sys.path.insert(0, '/usr/share/yum-cli')
try:
    import yummain
    yummain.user_main(sys.argv[1:], exit_code=True)
except KeyboardInterrupt as e:
    print >> sys.stderr, "\n\nExiting on user cancel."
    sys.exit(1)

 修改后:

[root@localhost ~]# vi /usr/bin/yum

[root@localhost ~]# cat /usr/bin/yum
#!/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:

   %s

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
%s

If you cannot solve this problem yourself, please go to
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

""" % (sys.exc_value, sys.version)
    sys.exit(1)

sys.path.insert(0, '/usr/share/yum-cli')
try:
    import yummain
    yummain.user_main(sys.argv[1:], exit_code=True)
except KeyboardInterrupt, e:
    print >> sys.stderr, "\n\nExiting on user cancel."
    sys.exit(1)
[root@localhost ~]#

到此yum 已可用,检查

# yum 已可用
[root@localhost ~]# yum --version
3.4.3
  Installed: rpm-4.11.3-32.el7.x86_64 at 2023-09-21 16:12
  Built    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> at 2017-11-13 15:51
  Committed: Panu Matilainen <pmatilai@redhat.com> at 2017-11-13

  Installed: subscription-manager-1.20.10-1.el7.x86_64 at 2023-09-21 16:14
  Built    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> at 2018-01-30 22:04
  Committed: Kevin Howell <khowell@redhat.com> at 2018-01-30

  Installed: yum-3.4.3-158.el7.noarch at 2023-09-21 16:12
  Built    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> at 2017-11-26 22:21
  Committed: Valentina Mukhamedzhanova <vmukhame@redhat.com> at 2017-11-26
[root@localhost ~]#

 

[root@localhost ~]# yum
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
You need to give some command
Usage: yum [options] COMMAND

List of Commands:

check          Check for problems in the rpmdb
check-update   Check for available package updates
......
......
--cves=CVES           Include packages needed to fix the given CVE, in
                      updates
--sec-severity=SEVS, --secseverity=SEVS
                     Include security relevant packages matching the
                     severity, in updates

Plugin Options:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值