Environment: Aws EC2, redhat – centos
While installing awscli, due to incompatibility between awscli2 and python2.6 , I had to install python 3.7. But while doing this i removed all existing python packages including default system usage onces.
Now when I try to execute yum, it gives following error:
/usr/bin/python: bad interpreter: No such file or directory
Then, I installed python2.6 (and also tried 2.7) manually with following way.
sudo wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
sudo tar xzf Python-2.7.9.tgz
cd Python-2.7.9
sudo ./configure --enable-optimizations
sudo make & sudo make install
But again it gives same error:
When i change default python directory
sudo vim `which yum`
/usr/local/bin/python2.7
and tried also /usr/local/bin/python2.6
Also for 2.7 I tried adding following
sys.path.append('/usr/local/bin/python2.7/site-packages')
sys.path.append('/usr/lib64/python2.7/site-packages')
But now it gives following error.
No module named yum
3
Answers
I’m not sure if this is a valid answer, but I’ve put a few hours into this and the conclusion is to reinstall the system.
Other way may possibly be a thorough investigation of all package dependencies, downloading the rpms manually and updating using rpm command, but that is another few hours. Since we are going to reinstall the whole system pretty soon, it’s not a big concern.
We will use Debian 11, not CentOS. CentOS 7 is really old.
It needs to be noted that this problem would not occur, if the new Python would be "altinstall"ed instead of "install"ed in the first place.
Well, you know which python it needs (the path) – presumably python
2.6
on your original system:And you know where python gets installed into, when built from scratch:
In general it’s not a good idea to remove your system’s python installation. This is why there are tools like
pyenv
for instance.Back to your problem – You could create an alias for the time being, either temporarily in your shell or persistently in your
~/.bashrc
(assuming you usebash
):This will, for your user and your session, make
python
link to/usr/local/bin/python2.6
.By the way, problems like this:
I can only recommend
pyenv
to manage multiple python versions in your system and a python dependency management tool like e.g.poetry
to define dependencies and install them correctly in terms of python version, constraints and dependencies of dependencies.I meet this issue and i run this bash shell to reinstall yum by
execute sh /install/reinstall-yum.sh
on Centos 7 (Core). Create Folder and file with conent ofreinstall-yum.sh
as below: