首页 > 解决方案 > 没有名为 yum 的模块

问题描述

我用 Python 2.7 尝试了解决方案@yum---没有名为 yum 的模块“没有名为 yum 的模块”,但没有帮助,听起来 yum 模块不是普通的 Python 模块,需要针对你的 Python 2.7 构建 yum安装,任何人都可以提供有关如何执行此操作的指导吗?

机器详情:

[usernames@machine]$ cat /etc/*elease
LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Oracle Linux Server release 6.6
Red Hat Enterprise Linux Server release 6.6 (Santiago)
Oracle Linux Server release 6.6

错误:-

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

   No module named yum

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.7.12 (default, Aug 11 2016, 12:02:22) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)]

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

标签: pythonlinuxredhatyumrhel

解决方案


看起来被破坏的是系统Python in /usr/bin,它知道在哪里可以找到 RHEL 安装的 Python 模块和共享对象。所以你需要重新安装 RHEL python rpms,而不仅仅是 yum。

RHEL/usr/bin/python用于它的许多实用程序。 yum是一个 Python(包装器)脚本。

看起来您使用的是 RHEL 6。所以 /usr/bin/python 必须是 2.6。这就是 RHEL 6 附带的。(对于 RHEL 7,它需要是 2.7.5)

因此,要解决问题,您需要从 RHEL rpms 重新安装系统 Python。为了使系统正常工作,/usr/bin/python 不能是 Python 的任意版本。

yum rpm 只会将 yum 文件重新安装到原始路径,但您需要从正确目录加载模块的 RHEL /usr/bin/python。rpm 不会安装 Python 意义上的模块。此外,还有许多其他模块具有共享库依赖项,例如 DBus 接口。

因此,为您的发行版获取 RHEL python-* rpms。您需要下载它们,或使用 ISO/DVD。rpm 本身不知道如何通过网络访问软件仓库,这是 yum 的工作,因此您必须手动完成。

或者,如果您有另一个系统运行相同版本的 RHEL,您可以复制文件。您可以使用rpm -Va获取属于已修改的 rpm 的所有文件的列表。在正常操作期间,有许多文件会被修改。

(故事的寓意,不要覆盖/usr/bin/python,/usr/bin/python2。RHEL(和其他平台,Fedora等)依赖于系统python才能正常工作。)


推荐阅读