CentOS comes with Python deleted && YUM error repair

Existing situation: the Python 2.7.5 that comes with the CentOS7.3 system is deleted, and the yum command throws No module named yum

Reference link: https://my.oschina.net/u/1414906/blog/296759

Simple case handling##

This situation means that the Python version has been reinstalled or upgraded, but the built-in Python has not been deleted.

# 1. First find the location of the old version of Python,Will return all python positions
➜  ~ whereis python

# 2. Go test,Which is correct
➜  ~ python2.7-c "import yum"

# 3. Assuming the above is normal,No error
➜  ~ vim /usr/bin/yum

# 4. Modify the head
#! /usr/bin/python --> #!/usr/bin/python2.7

# 5. In theory this is fine

If the built-in Python is deleted, the above will no longer be valid##

Reinstall Python

installation####

➜  ~ cd ~/tmp
➜  ~ wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
➜  ~ tar zxvf Python-2.7.5.tgz
➜  ~ cd Python-2.7.5
➜  ~./configure   # ??Need to add one here??
➜  ~ make&&make install
➜  ~

Establish soft connection####

# Back up the original python first(if so)
➜  ~ mv /usr/bin/python /usr/bin/python.bak

# Assuming python2.7 is the currently installed version
➜  ~ ln -s /usr/local/bin/python2.7/usr/bin/python

# View python version
➜  ~ python --version

# Should be normal in theory

! ! The key fix! !

**Go to the CentOS installation CD or ISO image to find the following files, Requires the same system version. **

python-2.7.5-48.el7.x86_64.rpm
python-devel-2.7.5-48.el7.x86_64.rpm
python-libs-2.7.5-48.el7.x86_64.rpm
python-urlgrabber-3.10-8.el7.noarch.rpm
yum-3.4.3-150.el7.centos.noarch.rpm
# View system version
➜  ~ cat /etc/system-release
CentOS Linux release 7.3.1611(Core)
# Coincidentally, I just found the mirror of NetEase
http://mirrors.163.com/centos/7.3.1611/os/x86_64/Packages/

# Just search for the packages above. Find wget and download it
# Upgrade
➜  ~ rpm -Uvh *.rpm
# Redo yum cache
➜  ~ yum clean all
➜  ~ yum makecache

# In theory, it can be used normally

Recommended Posts

CentOS comes with Python deleted && YUM error repair
Centos6.7 comes with python upgrade to
Centos 6.10 reinstall python and yum
CentOS7 repairs python to save yum
Error compiling mariadbpp with cmake under centOS7
CentOS + Python3.6+
Centos 7.5 python3.6
Where is the IDE that comes with Python