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.

  • 1
    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. 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/_weakrefset.py", 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/. 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 packages.ubuntu.com for your version of Ubuntu. If so, then the filename of the .deb file will also change in the dpkg command.

  • Wouldn't aptitude reinstall python2.7-minimal be much easiser? 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. 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
  • 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.

  • 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

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.