2
votes

I tried the solution @yum---no module named yum and "No module named yum" with Python 2.7 but didn't help,it sounds like the yum module is not a stock Python module and need to build yum against your Python 2.7 install,can anyone provide guidance on how to do this?

machine details:

[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

Error:-

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
3
Did you upgrade python2 and override your system python?jgritty
Are you just trying to run yum?jgritty
@jgritty - am using python 2.7.2 on my machine ,that could be the reason?how to fix the issue?yes,I am trying to just run yumcarte blanche
You are running OEL6. You can get the latest supported python and python-libs from public-yum.oracle.com. Replace python-2.7.2 with these distro libs. You may also need to reinstall yum if the directory /usr/lib/python2.6/site-packages/yum and its contents were wiped out. Running rpm -V yum will show if any files are missing.alvits

3 Answers

1
votes

It appears what got clobbered was the system Python in /usr/bin, that knows where to find the python modules and shared objects installed by RHEL. So you need to reinstall RHEL python rpms, not just yum.

RHEL uses /usr/bin/python for many of it's utilities. yum is a Python (wrapper) script.

It looks like you are using RHEL 6. So /usr/bin/python must be 2.6. That's what RHEL 6 shipped with. (For RHEL 7 it needs to be 2.7.5)

So, to fix things you need to reinstall the system Python from the RHEL rpms. For the system to work correctly, /usr/bin/python can't be an arbitrary version of Python.

The yum rpm will just reinstall the yum files to the original path but you need the RHEL /usr/bin/python which is loading the modules from the correct directories. The rpm will not install the module in the Python sense. Also, there are many other modules with shared library dependencies for things like DBus interfaces.

So obtain the RHEL python-* rpms for your release. You'll need to download them, or use the ISO/DVD. rpm by itself doesn't know how to access software repos over the network that's yum's job so you have to do it manually.

Alternatively if you have another system running the same version of RHEL you could copy files over. You can use rpm -Va to get a list of all files that belong to rpms that have been modified. There are a number of files that get modified during normal operation.

(Moral of the story, don't overwrite /usr/bin/python, /usr/bin/python2. RHEL (and other platforms, Fedora, etc.) depend on the system python to work correctly.)

0
votes

Well, assuming rpm is not broken - you could do something like this:

First:

rpm -q yum

for retrieving installed ( but broken ) yum package. For example on my Centos7 i get next result: yum-3.4.3-154.el7.centos.1.noarch.rpm

But that's not all. You should remove part between .el7 and noarch. Then, you can proceed to second step

Second:

rpm -qpR <yum package name>

or:

rpm -qR yum

for getting yum dependecies list.

And the last one:

rpm -Uvh <packagenames>
-1
votes

Apparently you replaced the system version of Python.

Don't do that. Use virtualenv, pip, and/or other tools to run custom versions of Python when you need them.

Try to put back the official distro Python installation.