Reinstalling python on CentOS to be able to use yum

27,222

Solution 1

I'm surprised you were able to remove the python package. It has so many dependencies on a RHEL/CentOS system, that there's a good chance you removed far more than python. Running yum remove python on one of my CentOS systems yields:

Dependencies Resolved

====================================================================================================================
 Package                                 Arch           Version                             Repository         Size
====================================================================================================================
Removing:
 python                                  x86_64         2.4.3-46.el5                        installed          72 k
Removing for dependencies:
 AcronisAgentLinux                       x86_64         41.0.16-1                           installed          13 M
 BackupAndRecoveryAgent                  x86_64         11.0.17318-1                        installed         154 M
 GConf2                                  i386           2.14.0-9.el5                        installed         4.6 M
 .
 .
 .
 yum-metadata-parser                     x86_64         1.1.2-3.el5.centos                  installed          55 k
 yum-security                            noarch         1.1.16-21.el5.centos                installed          60 k
 yum-updatesd                            noarch         1:0.9-2.el5                         installed          55 k
 yum-utils                               noarch         1.1.16-21.el5.centos                installed         194 k
 zsh                                     x86_64         4.2.6-6.el5                         installed         3.6 M

Transaction Summary
====================================================================================================================
Remove      493 Package(s)
Reinstall     0 Package(s)
Downgrade     0 Package(s)

Is this ok [y/N]: (Heck-no!)

Did you actually let the process remove hundreds of installed packages?

If you only removed a single package, you would need to download the python RPM for your particular version of CentOS. If this was CentOS version 5.8 on 64-bit, for instance, you'd find the current package name in the CentOS repository... Look for python-2.4.3-46.el5.x86_64.rpm

To install that particular package, use wget http://mirror.anl.gov/pub/centos/5.8/os/x86_64/CentOS/python-2.4.3-46.el5.x86_64.rpm to download the individual package. Use rpm -ivh python-2.4.3-46.el5.x86_64.rpm to actually install it with the RPM package manager.

Solution 2

Building your own Python back didn't work for me. This works:

(note this is for a Centos 6x host, which now uses Python2.6, but it's the same thing)

wget  http://mirror.centos.org/centos/6/os/x86_64/Packages/yum-3.2.29-40.el6.centos.noarch
wget  []://mirror.centos.org/centos/6/os/x86_64/Packages/python-devel-2.6.6-51.el6.x86_64.rpm
wget  []://mirror.centos.org/centos/6/os/x86_64/Packages/python-2.6.6-51.el6.x86_64.rpm
wget  []://mirror.centos.org/centos/6/os/x86_64/Packages/python-libs-2.6.6-51.el6.x86_64.rpm

rpm -Uvh --replacepkgs *.rpm

And then Yum will work again.

Solution 3

If you have make&&gcc installed:

wget http://www.python.org/ftp/python/2.4/Python-2.4.tar.bz2
tar jfvx Python-2.4.tar.bz2
cd python
./configure
make all
make install

Then you can have your Python back.

Share:
27,222

Related videos on Youtube

Umit
Author by

Umit

Updated on September 18, 2022

Comments

  • Umit
    Umit over 1 year

    Yesterday I accidentally removed the python package using "yum remove" on a CentOS server. After then I realized yum was dependant on python and I could no longer use yum. I think I need to reinstall python to fix the problem. How can I do this without using yum?

    • Ramchandra Apte
      Ramchandra Apte almost 12 years
      this is not a programming question
    • Ramchandra Apte
      Ramchandra Apte almost 12 years
      you can compile Python from source if you have a compiler installed and make and autoconfigure
    • Katriel
      Katriel almost 12 years
      You may find that your question gets better results on ServerFault =)
  • user426034
    user426034 almost 7 years
    I did have the same kind of incident when porting to Python3 in order to install a Python Webserver on Apache. I discovered that Yum was Python2 only. I have been looking for a wget solution to recover Yum. Thanks AndyD! I am on VM Centos7 though but I guess it shouldn't be an issue. A bit off topic but I am left with a option to install both Python versions in /usr/local directory and to point Python2 to system and Python3 for Apache.
  • zzapper
    zzapper almost 6 years
    when i had this issue, wget/curl didnt work either but fortunately scp did