Problem description
In useyum
When commanding, the following error occurs:
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.18 (default, Nov 11 2024, 12:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
Cause of the problem
This problem is usually caused by one of several reasons:
Python version changes:
yum
Depend on the Python version, while the default Python on the system may be changed to Python 3, or Python 2 is upgraded or replaced, resulting inyum
The required module cannot be found.Missing dependency module:
yum
The Python modules that depend on (e.g.urlgrabber
) may have been deleted by mistake, or these modules cannot be found due to environment configuration errors.Symbol link error: In CentOS,
yum
Used by default/usr/bin/python
To call Python. If the symbolic link points to the wrong version of Python (such as Python 3), it will causeyum
Not working properly.
Solution
Solution 1: Fix Python Symbol Links
Check the current Python version symbolic link:
ls -l /usr/bin/python
if
/usr/bin/python
Pointing to other versions (such as Python 3), you need to switch it back to Python 2.7.Will
/usr/bin/python
Point to the system's default Python 2.7:
Reasons and prerequisites for effective entry:
-
yum
Rely on the Python version, so you need to ensure/usr/bin/python
Symbol links point to Python 2.7. If the symbolic link points to Python 3,yum
The corresponding module will not be found. - The premise of this solution is that there is still Python 2.7 installed in the system and it has not been deleted. If Python 2.7 is deleted, you need to reinstall it first.
Scenario 2: Reinstall the Python module
Install
yum
Depend on Python modules:
yum install python2 python-urlgrabber
This command reinstalls Python 2 and its required modules to ensure
yum
Can run normally.if
yum
It cannot be used by itself, you can try to install it manually:
rpm -Uvh --replacepkgs /centos/7/os/x86_64/Packages/python-urlgrabber-<version>.rpm
Will
<version>
Replace with the appropriate version number.
Solution 3: Usednf
replaceyum
dnf
yesyum
The subsequent version of has better dependency management and performance optimization functions. ifyum
Can't be repaired, you can consider installing and usingdnf
:
Install
dnf
:
rpm -Uvh /centos/7/os/x86_64/Packages/dnf-<version>.rpm
Will
<version>
Replace with the appropriate version number.use
dnf
Perform package management operations:
dnf update
Summarize
The root cause of this problem is usually the system's Python environment changes, resulting inyum
The dependent module cannot be loaded correctly. The most common solution is to fix Python's symlinks to point to Python 2.7, or reinstall the necessary Python modules. For situations that cannot be repaired, you can also consider using itdnf
As an alternative.
This is the end of this article about the solution to the Yum crash by upgrading python. For more related content on upgrading python, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!