I accidentally deleted /usr/bin/python. How do I restore it?
Trying to set the default Python version to 2.7, I ran this command:
sudo rm /usr/bin/python*
Now when I type python
or python2.7
, I see these error messages:
bash: /usr/bin/python: No such file or directory
bash: /usr/bin/python2.7: No such file or directory
What happened? Should I have run the rm
command? How can I undo it?
Solution 1:
Well, isn't normal that if you remove an executable, the system can't find it anymore?
/usr/bin/python
is a symlink provided by the python-minimal package. You can restore it reinstalling the package:
sudo apt-get install --reinstall python-minimal
Solution 2:
If you have python2.7-minimal
(or any of the other variants) installed, you should have the file /usr/bin/python2.7
present. Normally, /usr/bin/python
will be symlinked to this file, so that a simple call of python
actually ends up running /usr/bin/python2.7.
me@banshee:~$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root 9 Apr 17 2012 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root 9 Apr 17 2012 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 2989480 Aug 1 01:40 /usr/bin/python2.7
If you do have /usr/bin/python2.7
but you're missing /usr/bin/python
, you can simply recreate it from the command line:
you@yourbox:~$ sudo ln -s /usr/bin/python2.7 /usr/bin/python
If you're missing /usr/bin/python2.7
, you'll need to reinstall it (again) as proposed by the other answers. Please post back here if that's the case.
Solution 3:
From a terminal, type sudo apt-get install --reinstall python2.7