/usr/bin/python: bad interpreter: No such file or directory (Removed python rpms now python doesn't work and yum doesn't work)
Search the web for the appropriate Python RPMs, download them manually eg. using wget
or curl
and install them manually using rpm -i
.
From your comments I see that you have another machine with the same CentOS release, so you are lucky :). You can obtain exact information which packages to install. On that other machine, type
rpm -q -R yum
This will list all yum
dependencies. For example, on an old release of CentOS I have access to, it lists the following:
/usr/bin/python
config(yum) = 3.2.29-40.el6.centos
pygpgme
python >= 2.4
python(abi) = 2.6
python-iniparse
python-sqlite
python-urlgrabber >= 3.9.0-8
rpm >= 0:4.4.2
rpm-python
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PartialHardlinkSets) <= 4.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(VersionedDependencies) <= 3.0.3-1
yum-metadata-parser >= 1.1.0
yum-plugin-fastestmirror
rpmlib(PayloadIsXz) <= 5.2-1
You can ignore the entries that don't have python
in their name as you didn't uninstall them. You can also ignore the python(abi)
entry as it's just a feature provided by python
package. So what is left is:
python >= 2.4
python-iniparse
python-sqlite
python-urlgrabber >= 3.9.0-8
rpm-python
Then for each of these packages run
rpm -q <packagename>
It will give you the exact filename/version of the package installed. For example, on the machine I have rpm -q python
outputs python-2.6.6-36.el6.x86_64
and rpm -q python-iniparse
outputs python-iniparse-0.3.1-2.1.el6.noarch
. So you have to look exactly for these filenames in CentOS repositories. You can find the addressess of the repositories in files that are located within the /etc/yum.repos.d
directory.
Download these RPM files and install them.
If yum
still doesn't work, it is possible that Python packages depend on each other and something is still missing. Check the following on the other machine:
rpm -qa | grep python
and install all the indicated packages on the broken machine.
Related videos on Youtube
Jono
Updated on September 18, 2022Comments
-
Jono over 1 year
I was uninstalling OpenSSH with the following command:
for i in $(rpm -qa | grep openssh);do sudo rpm -e $i --nodeps;done
Then for some reason, I don't know why I thought this was a good idea, I ran this command to remove python:
for i in $(rpm -qa | grep python);do sudo rpm -e $i --nodeps;done
Now when I run sudo yum update I get the following:
bash: /bin/yum: /usr/bin/python: bad interpreter: No such file or directory
First line of /bin/yum reads:
#!/usr/bin/python
I then checked the /usr/bin directory for python
ls -lha /usr/bin | grep python
and got back nothing.
-
Jono over 3 yearsI found python 2.7.5 rpm and was able to install it via rpm -i. I can now run python and get python 2.7.5 interpreter
-
Jono over 3 yearsHowever, when I do a sudo yum update command I get the following error: Traceback (most recent call list): File "/bin/yum", line 29, in <module> yummain.user_main(sys.argv[1:], exit_code_True) File "/usr/share/yum-cli/yummain.py" line 236, in user_main errcode = main(args) File "/usr/share/yum-cli/yummain.py" line 90, in main base.getOptionsConfig(args) File "/usr/share/yum-cli/cli.py" line 161, in getOptionsConfig disabled_plugins=self.optparser._splitArg(opts.disabledplugins)) TypeError: _getConfig() takes exactly 1 argument (9 given)
-
raj over 3 yearsProbably you need some additional Python modules as well.
-
raj over 3 yearsI just ran
rpm -q -R yum
on some old CentOS I have access to and it told me thatyum
depends on packagespython-iniparse
,python-sqlite
,python-urlgrabber
andrpm-python
. When you uninstalled everything python-related, you probably uninstalled them, so you need to install them again. -
Jono over 3 yearsI actually already installed python-iniparse, python-urlgrabber, and rpm-python. I did not do python-sqlite yet however. I found python-sqlite here:
https://rpmfind.net/linux/rpm2html/search.php?query=python-sqlite&submit=Search+...&system=&arch=x86_64
. when I tried to dorpm -ivh python-sqlite.rpm
it failed on a few two dependencies: libsqlite3.so.0 & python(abi) = 2.4. I am having trouble finding those rpms, do you have a link to the dependencies for python-sqlite? -
raj over 3 yearspython(abi)=2.4 means it's a module for python 2.4, and you have 2.7.5. You must find a correct version for your system.
-
Jono over 3 yearsIt's weird because when I run
rpm -q -R yum
it has a number of results but this one in particular confuses me:python(abi) = 2.7
-
raj over 3 yearsIt means your
yum
requires python version 2.7. -
Jono over 3 yearsYet another dependency when trying to do
rpm -ivh pythonabi.rpm
, python < 2.4 is needed by pythonabi-1:2.3-3.el4.at.x86_64. I triedrpm -ivh python2.4-2.4-1pydotorg.src.rpm
and it resulted in the following message:Updating / Installing... 1. python2.4 [100%] warning: user jafo does not exist - using root `` group jafo does not exist
Now it still says failed dependencies when I try to rpm install pythonabi with same message of:python < 2.4 is needed by pythonabi-1:2.3-3.e14.at.86_64
-
raj over 3 yearsI would suggest you ask someone using the same CentOS version as you (maybe on some CentOS help forum?) that they give you exact versions/filenames of the RPMs you need to install.
-
Jono over 3 yearsI have another machine that is CentOS 7.9 (same as machine with issue). What command can I run to get all the .rpms needed to fix the yum issue?
-
raj over 3 yearsI have edited my answer to include instructions.
-
raj over 3 yearsIf python-sqlite is not listed by
rpm -q -R yum
then you don't have to install it. Install whatever is installed on the other machine, do not follow literally the example I have shown. -
raj over 3 yearsIf there are still errors, you may try to do
rpm -qa | grep python
on the other machine and install all these packages, as the python packages may depend on each other, and you uninstalled all of them. -
Jono over 3 yearsFrom what I can tell the results from
rpm -q -R yum
are now identical but I am still getting the original error when trying to use any command withinyum
-
raj over 3 yearsIt's not the results of
rpm -q -R yum
that are important to be identical, it's the actual installed packages that must be identical.rpm -q -R yum
tells you what should be installed for yum to work, and not what is. Checkrpm -qa | grep python
-
Jono over 3 yearsI did
rpm -q python
,rpm -q python-iniparse
for each item from therpm -q -R yum
results and those version matched/were install on both now.rpm -qa | grep python
are greatly different, working yum server (server2), has over 100 items, while broken yum server (server1), has only 14 items -
raj over 3 yearsSomething from those 100 items must be important. Try run
rpm -q -R <packagename>
on each item fromrpm -q -R yum
output, maybe you can determine what it is.