Remove clearly and reinstall python on CentOS
Asked Answered
D

2

5

Today I messed up the versions of Python on my CentOS machine. Even yum cannot work properly. I made the mistake that I removed the default /usr/bin/python which led to this situation. How could I get back a clear Python environment? I thought remove them totally and reinstall Python may work, but do not know how to do it. Wish somebody could help!

Dora answered 24/10, 2017 at 16:20 Comment(5)
You just deleted /usr/bin/python? if so, copy it from another machineKelby
What exactly did you do? You simply replace that executable with a different python executable? There are also executables there that should be named for the specific version of Python, e.g. /usr/bin/python2.6 (in CentOS 6) -- You can try copying that file to /usr/bin/python assuming you did not overwrite those as well.Novelize
I deleted the default /usr/bin/python and made a soft link /usr/bin/python to /usr/bin/python2.7. I think copying one from another machine would help.Dora
Dont try this, or you'll end up buying this: keepcalmstudio.com/gallery/poster/1BLAEVHHolleran
luckily, it's just a virtual machine, thx bro.Dora
M
9

The yum package manager is relies on an underlying tool called rpm, which does not require Python. You can use that to re-install the system Python package.

You can use this to reinstall the base python package from a CentOS mirror:

rpm -ivh --replacepkgs --replacefiles http://mirror.centos.org/centos/6/os/x86_64/Packages/python-2.6.6-66.el6_8.x86_64.rpm

For example:

# rm -f /usr/bin/python*
# yum version
bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory
# rpm -ivh --replacefiles --replacepkgs http://mirror.centos.org/centos/6/os/x86_64/Packages/python-2.6.6-66.el6_8.x86_64.rpm
Retrieving http://mirror.centos.org/centos/6/os/x86_64/Packages/python-2.6.6-66.el6_8.x86_64.rpm
warning: /var/tmp/rpm-tmp.DCR7QF: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                ########################################### [100%]
   1:python                 ########################################### [100%]
# yum version
Loaded plugins: fastestmirror, ovl
Installed: 6/x86_64                 131:0e17bede37a026e5f95d6cb7e185701b989fa47d
Group-Installed: yum                 14:973b685dc3deb5d8f00cdb3ec97022064b5ff793
version
Massingill answered 24/10, 2017 at 16:50 Comment(4)
@OscarJavierJimenez, I think you have misunderstood this answer. This does not remove the base Python. It reinstalls the base python after it has been removed or replaced, as in the original question.Massingill
Yes, you are right, I tried to answer another question in another post. Sorry, it was late.Romaromagna
this is probably not a valid solution since the OP mentioned that yum is not workingGaribaldi
@MayAnneLuyun The reason this answer uses rpm instead of yum is because yum requires Python, but rpm does not.Massingill
A
-1

To install Python on CentOS: sudo yum install python2/3 (select the version as per requirement) To uninstall Python on CentOS: sudo yum remove python2/3 (select the version as per your requirement) To check version for python3(which you installed): python3 --version To check version for python2 (which you installed): python2 --version

Adalie answered 19/8, 2020 at 6:22 Comment(1)
This is not a valid solution because OP indicated they are unable to use yum.Heterologous

© 2022 - 2024 — McMap. All rights reserved.