Daily Latest Tech Update

Yum commands fail with error “No module named yum” in RHEL 7

  • Share

Yum commands fail with following error “No module named yum” in Red Hat Enterprise Linux 7 (RHEL 7). It is quite troublesome. There are some solution out there but none any of them work. After several trial and error, i finally get the yum back to alive again.

[[email protected]]# yum updateThere was a problem importing one of the Python modulesrequired to run yum. The error leading to this problem was:   No module named yumPlease install a package which provides this module, orverify that the module is installed correctly.It's possible that the above module doesn't match thecurrent version of Python, which is:2.7.16 (default, Apr  2 2019, 16:59:02)[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]If you cannot solve this problem yourself, please go tothe yum faq at:

The resolutions

This issue supposedly caused by the system’s default of python version provided by Red Hat has been changed or removed. The system’s default of python version is 2.7.5. So, you need to remove any existing python version 2. You can manually remove python installation or use below script. I have made this script to remove any python installation.

#!/bin/bashprefix='/usr/local/'pyver='2.7'rm -rf -I \    ${prefix}bin/python${pyver} \    ${prefix}bin/pip${pyver} \    ${prefix}bin/pydoc \    ${prefix}bin/include/python${pyver} \    ${prefix}lib/libpython${pyver}.a \    ${prefix}lib/python${pyver} \    ${prefix}bin/python${pyver} \    ${prefix}bin/pip${pyver} \    ${prefix}bin/include/python${pyver} \    ${prefix}lib/libpython${pyver}.a \    ${prefix}lib/python${pyver} \    ${prefix}lib/pkgconfig/python-${pyver}.pc \    ${prefix}lib/libpython${pyver}m.a \    ${prefix}bin/python${pyver}m \    ${prefix}bin/2to3-${pyver} \    ${prefix}bin/python${pyver}m-config \    ${prefix}bin/python${pyver}-config \    ${prefix}bin/idle${pyver} \    ${prefix}bin/pydoc${pyver} \    ${prefix}bin/pyvenv-${pyver} \    ${prefix}share/man/man1/python${pyver}.1 \    ${prefix}include/python${pyver}m    ${prefix}bin/pydoc ## WARN: skip if other pythons in local exist.

You only need to change the value of prefix and pyvar.

Steps to resolve

List all of the python installation folder.

# ls -al `which python`lrwxrwxrwx 1 root root 7 Apr  4 10:17 /usr/bin/python -> python2#

See also  How to block Googlebot in Nginx

Change the value of pyvar and prefix.

Make a shell script, i.e.: and use script above. Change the file mode to executable. And run the script.

# touch && nano chmod +x ./

Repeat above steps until you don’t have any python installation left.

Download latest python 2.7.5 from and any its dependencies:

Install it with this command.

rpm -Uvh --force <rpm package name>

Download latest yum from and any its dependencies:


If you have any question do not hesitate to leave a comment below.

Originally posted 2019-04-04 04:35:11.

  • Share

Leave a Reply

Your email address will not be published.