Unfortunately I deleted the /usr/bin/python in my ubuntu 12.04 I went to /usr/bin/ and run

ls -al

then I got

lrwxrwxrwx 1 root root      64 Jul 13 14:58 python -> /Library/Frameworks/Python.framework/Versions/Current/bin/python 

How do I link that python so that I can get python in terminal on running python

I also reinstalled python by

apt-get --purge --reinstall install python

I tried adding sym link like ln -s /usr/lib/python2.7/ /usr/bin/python then it thrown in ln: failed to create symbolic link/usr/bin/python': File exists`

  • 3
    What? "python -> /Library/Frameworks.." Looks like a Mac OS X path. How did you get that there? – gertvdijk Jul 15 '13 at 6:29
  1. Boot up in recovery mode or something. I guess your current system state won't make it to the GUI without Python.

  2. Remove the current dead link.

    rm /usr/bin/python
  3. Recreate the link

    ln -s /usr/bin/python2.7 /usr/bin/python

Don't forget to prepend the commands with sudo if you aren't root at that point.

  • This is really helpful, it saved my day. – Karan Sharma Feb 15 '18 at 9:11

Use the following commands:

sudo unlink /usr/bin/python                     #to delete the previous symbolic link
sudo ln -s /usr/lib/python2.7 /usr/bin/python   #to recreate the new correct symbolic link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.