Remember the failure of linux centos7.3yum source

Remember a linux7.3yum source failure problem

Yum fails due to cheap upgrade of python

report 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.5 (default, Nov  2 2021, 21:34:44) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

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

image-20211105090142747

Because it’s so cheap, python has been deleted and installed, according to CSDN, various posts have not been adjusted

After a variety of operations to finally solve the problem, the operation began

1. First look at the system version

image-20211105090447682

[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core) 

2. Download the corresponding python package according to the system version

Official website address: https://www.python.org/downloads/

Find a linux with the same system version as your own to check the python version

image-20211105090820093

[root@localhost ~]# python -V
Python 2.7.5

3. Uninstall the current system python, yum dependencies

rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps 
whereis python |xargs rm -frv
whereis python 
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
whereis yum |xargs rm -frv

4. Re-download and install the python version of the corresponding system

4.1. Installation under linux

--- 安装依赖包
# cd /usr/local
# wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
# tar -xzvf Python-2.7.5.tgz
# cd Python-2.7.5
# ./configure --prefix=/usr/local/Python2.7.5 --enable-shared -enable-unicode=ucs4
# make
# make install
# python -V

4.2.python interpreter points to python2.7.5

# which python
# cd /usr/bin
# rm python
# ln -s /usr/local/Python2.7.5/bin/python python
# python -V  --执行报错

4.3. Solve python -V execution error

# cd /etc/ld.so.conf.d/
# echo "/usr/local/Python2.7.5/lib" > python2.7.conf
# ldconfig
# python -V

5. Find a server with good yum, pay attention to it!

Find a server with good yum function, the system version is the same as the bad one,
if not, build a virtual machine with the same system version as your own

5.1. Enter the command to find the site-packages package path

image-20211105091613067

[root@localhost ~]# python
Python 2.7.5 (default, Nov  6 2016, 00:28:07) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages']
>>> 
[root@localhost ~]# 

python
import sys
print sys.path

输入 ctrl+D 退出

image-20211105091901863

image-20211105091945793

5.2. Package and download all the files under the two paths of /usr/lib64/python2.7/site-packages' and '/usr/lib/python2.7/site-packages'

image-20211105093600342

5.3. Find /usr/share/yum-cli and download all the files in this directory

image-20211105092902099

5.4. After packaging and downloading, switch back to the server where our yum is broken, and find the path /usr/local/Python2.7.5/lib/python2.7/site-packages

image-20211105092528356

Here you can see that our corresponding directory is empty

Upload all the site-packages files you just downloaded here

image-20211105092646290

5.5. Upload the /usr/share/yum-cli just downloaded to /usr/share/yum-cli

image-20211105093012777

Check the /usr/share directory to see if there is a yum-cli directory. If there is no yum-cli directory, create one and transfer the file from the good server. If there is, delete all the files in it, and upload it server

6. Finally, execute yum to solve it perfectly. The best solution is to find a good one, and copy the site-packages and /usr/share/yum-cli files in its python directory directly to the hanging one

Don’t download all kinds of plug-ins and rpm installations, they are all fake and useless, ctrl c ctrl v, changing ctrl c ctrl v from a good server to a bad one is better than anything

image-20211105093151057

Guess you like

Origin blog.csdn.net/qq_37349379/article/details/121156546