Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I accidentally overwrote my /usr/bin/python2.7 executable. When I try to reinstall with

aptitude reinstall python2.7

It fails because, python2.7 is required to install python2.7. I'm in a bind. I do have python2.6 installed, but aptitude isn't work with that.

Anyideas? I really just need to replace that executable, but I can't find it anywhere.

share|improve this question

migrated from Jun 4 '11 at 16:29

This question came from our site for professional and enthusiast programmers.

Probably you need to reinstall some more basic package like python2.7-minimal or similar. You can find out via dpkg -S /usr/bin/python2.7 which package you need to reinstall. Since I'm not using Ubuntu myself, I can't give a definite answer at the moment. – Sven Marnach Jun 4 '11 at 16:24
@Sven Marnach You're exactly right. On Ubuntu 11.04: $ dpkg -S /usr/bin/python2.7 python2.7-minimal: /usr/bin/python2.7 @user475119 If you try aptitude install python2.7-minimal, does it work? – Jacinda Jun 4 '11 at 16:29
sudo dpkg -i python-minimal_2.7.1-0ubuntu5_all.deb and similar give.. File "/usr/lib/python2.7/", line 5, in <module> from _weakref import ref ImportError: No module named _weakref – user475119 Jun 4 '11 at 17:02
@user: Try the following: move python-minimal_2.7.1-0ubuntu5_all.deb to an empty directory and call dpkg -x python-minimal_2.7.1-0ubuntu5_all.deb . in this directory. This will unpack the package contents. Then do sudo cp -a usr/bin/python2.7 /usr/bin/. – Sven Marnach Jun 4 '11 at 18:01
tmp$ sudo cp -a usr/bin/python2.7 /usr/bin/. [sudo] password for gbc: cp: cannot stat `usr/bin/python2.7': No such file or directory – user475119 Jun 5 '11 at 1:43

You can download the package needed from here:

then use dpkg to install it (I don't think it needs python to run):

sudo dpkg -i python-minimal_2.7.1-0ubuntu5_all.deb

If you are not running Ubuntu 11.04, you may need to download the correct version from for your version of Ubuntu. If so, then the filename of the .deb file will also change in the dpkg command.

share|improve this answer
Wouldn't aptitude reinstall python2.7-minimal be much easiser? – Sven Marnach Jun 4 '11 at 16:58
As the original poster mentioned, aptitude fails because it uses python, which was indeed overwritten, which was the problem in the first place. ;-) – Victor Jun 4 '11 at 17:03
@Victor: aptitude reinstall python2.7 fails because python2.7 depends on python2.7-minimal. Aptitude doesn't depend on Python. – Sven Marnach Jun 4 '11 at 17:15
Oh I see... That's not what I interpreted it as saying. But why would it need python to install python. That doesn't make any sense. Am I misunderstanding you? – Victor Jun 4 '11 at 17:24
Interesting. I basically overwrote /usr/bin/python2.7 with /usr/bin/python2.6 while trying to symlink and be distracted by the dog and the kids. Getting import error when running dpkg, apt-get or aptitude with the various packages including minimal: ImportError: No module named _weakref – user475119 Jun 4 '11 at 17:26

A similar problem was resolved using the following commands:

sudo dpkg --configure -a
sudo apt-get -f install
sudo apt-get --fix-missing install
sudo apt-get clean all
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get clean all
sudo apt-get autoremove
share|improve this answer
Thanks. You guys are so positive and helpful. Thanks to all. – user475119 Jun 4 '11 at 18:39
The first command here gives the import error: ImportError: No module named _weakref. I have a critical need for python2.6 on my system, and clearly one for 2.7, and the two things don't work with the other versions. I think this problem was bound to happen at some point. Going to rebuild/downgrade Ubuntu to the most recent that uses python2.6, Then my system will use just 2.6, and I should be good. (For other projects that might need 2.7, I'll use virtualenv.) Thanks again for all the help. – user475119 Jun 4 '11 at 18:42

did you look in /usr/bin? there maybe other versions of python (other executables) you could create a python2.7 symlink to

or copy the bin from another machine of the same arch.

share|improve this answer
I've checked my other machines, but don't have anything running Ubuntu 11.04, or with Python2.7. I took backups regularly up to when I upgraded this system to 11.04. I have basically, made it through a long career not totally hosing my system, and it looks like my good luck is catching up to me. – user475119 Jun 4 '11 at 17:50
If you have the full GNU tool chain, you can compile python from source, and just copy the bin into the directory. Compile it on another machine if you have to; python is an easy build. – tMC Jun 5 '11 at 2:59

You must log in to answer this question.

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