4

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?

1
  • 5
    Never remove system files like this. Why did you even consider doing this? Setting the default Python version on your system is not done by removing files, and you should not perform this change. Read this question: Changing Python default for more details.
    – gertvdijk
    Dec 28, 2012 at 12:37

3 Answers 3

7

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
0
4

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.

1
  • it appears that I also somehow deleted the usr/bin/python* ....since I am not expert in ubuntu and I don't know how the system works, I had to reinstall the whole system again..hope I will learn from my mistakes..thanks
    – Muhammad
    Nov 19, 2012 at 1:18
3

From a terminal, type sudo apt-get install --reinstall python2.7

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .