【问题标题】:Yum "cannot import name Errors" - Red Hat 4.4 with Python 2.6 / 2.7Yum “无法导入名称错误” - 带有 Python 2.6 / 2.7 的 Red Hat 4.4
【发布时间】:2018-08-17 07:16:30
【问题描述】:

我尝试运行的任何 yum 命令都会返回以下内容:

    There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   cannot import name Errors

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:
2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]

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

这就是我所做的和我所知道的:

操作系统是红帽 4.4.7018

我相信 Python 是 2.6,前段时间更新到 2.7(我怀疑这可能破坏了 yum)

python -V 返回 2.7.13

# ls -lrt /usr/bin/python*
-rwxr-xr-x. 1 root root 4864 Aug 18  2016 /usr/bin/python2.6
lrwxrwxrwx. 1 root root    6 Mar  8 13:16 /usr/bin/python2 -> python
lrwxrwxrwx. 1 root root   24 Mar  8 13:32 /usr/bin/python -> /usr/local/bin/python2.7

# ls /usr/bin/python*
/usr/bin/python  /usr/bin/python2  /usr/bin/python2.6

# ls /usr/local/bin/python*
/usr/local/bin/python2.7  /usr/local/bin/python2.7-config

我尝试在所有 phyton 上运行 import yum,只有 2.6 不会给我错误,所以我尝试将链接更改回 2.6(通过 python -V 验证以检查它是否返回到版本 2.6.6 ),yum 仍然返回“cannot import name Errors”错误。

另外,PATH 变量:

# echo $PATH

    /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/git/bin:/root/bin

/usr/bin/yum上配置的python是#!/usr/bin/python2.6,我试过改成/python,甚至/phyton2还是报错。

【问题讨论】:

    标签: python redhat yum rhel


    【解决方案1】:

    我不是 Linux 专家,但这看起来像 Red Hat 6(默认使用 python 2.6)[1]。 4.4 是 GCC 的版本。当您将 python 2.6 重新安装到位并且仍然需要 Python 2.7 时,然后通过 Software Collections 渠道安装后者 - 这将与 2.6 版本一起安装 2.7,而不是替换它以弄乱操作系统。

    [1]How to confirm RedHat Enterprise Linux version? [2]https://developers.redhat.com/products/softwarecollections/hello-world/#fndtn-python

    【讨论】:

    • 啊,是的,它是 6.7 版,谢谢!我已将 Symlink 改回 2.6,但仍然出现错误,所以我认为在 2.7 安装时 2.6 出现问题,我必须在重新安装 2.7 之前修复它?你认为我还应该继续重新安装 2.7 吗?我不知道
    • 我建议恢复到原来的操作系统状态,因为这样可能不会那么痛苦。 ://
    • 这是一个有一些重要生产配置的服务器,所以如果我们决定将它恢复到原来的状态会很痛苦:/但看起来我们正朝着那个方向前进:/跨度>
    【解决方案2】:

    旧版 red hat(6 及更早版本)中的 yum 命令适用于 python 2.6

    您是否使用 unlink /usr/bin/python 测试 yum 命令并添加从 /bin/python 到 /usr/bin/python2.6 的新链接?

    如果结果类似相同的错误,请尝试重新编译 python6 或更新服务器上的 yum pkgs

    【讨论】:

      猜你喜欢
      • 2016-04-09
      • 2019-07-14
      • 2018-11-24
      • 2013-05-13
      • 2014-01-29
      • 1970-01-01
      • 2015-07-10
      • 2018-10-19
      • 2016-12-03
      相关资源
      最近更新 更多