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

By a slip of the keys I issued the command:

sudo rm /usr/bin/python*

and with that the problems started. Python still starts, but when I now want to do anything with dpkg I get this error (entire error message not included as it is long):

AttributeError: 'module' object has no attribute 'pydebug'
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

so basically papyon/pydebug or dpkg seems to be causing a problem. I have tried things like

sudo apt-get -f install
sudo apt-get --fix-missing install

following the same problem mentioned in another forum:

but to no avail. It seems no matter what I do with dpkg I get the same error. I naively tried to this:

sudo cp /usr/lib/python2.7 /usr/bin/python2.7
sudo ln -s /usr/bin/python2.7 /usr/bin/python

but that did not work.

Any help here would be appriciated.

share|improve this question

migrated from Nov 15 '11 at 23:55

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

lol unlucky.... – Jakob Bowyer Nov 15 '11 at 23:33
Have you tried uninstalling Python and then re-installing it? – NullUser Nov 15 '11 at 23:37
removing it as we speak. Since I am only on a 3G connection it will take a little time before I can see the results of the install. Cheers. – Paul Nov 15 '11 at 23:40
Nope not possible: Processing was halted because there were too many errors. E: Sub-process /usr/bin/dpkg returned an error code (1) – Paul Nov 15 '11 at 23:46
up vote 3 down vote accepted

That's one hilarious slip of the fingers; I always like to use sudo echo /path/to/files/*glob* to see what files specifically I'm about to delete before I change the echo to rm. Now you've learned the lesson too! Fun.

Preaching aside, this shouldn't be too hard to fix, but it will take a few "passes". deb packages are ar(1) packages, and can be easily manipulated with ar(1):

$ ar xv /var/cache/apt/archives/python-papyon_0.5.5-1ubuntu1.3_all.deb
x - debian-binary
x - control.tar.gz
x - data.tar.gz

Try this:

mkdir /tmp/fixing_python
cd /tmp/fixing_python
ar xv /var/cache/apt/archives/<package_for_overwriting>
cd /
tar zxvf /tmp/fixing_python/data.tar.gz

Iterate that for every package you need to "fix". debsums(1)'s -c command line option might be helpful, if you've got debsums(1) installed.

Note that the tar command there is a bit "destructive" -- it'll overwrite whatever it needs to. If you'd rather see what everything will unpack, skip the cd / step beforehand, and tar(1) will unpack into the directory instead, giving you a chance to see what is done.

Once you've got everything unpacked that you need, I'd try hard to get dpkg(1) "happy" again through its own mechanisms. (The control.tar.gz contains control scripts that are executed on upgrades, installs, uninstalls, etc. I just had you skip all of them, thinking that once you've got Python re-installed, you can use dkpg(1) itself to fix the problems.)

We surely have different packages installed, but this might be helpful for you in finding out which packages need fixing:

$ dpkg -S /usr/bin/python*
python-minimal: /usr/bin/python
python2.6-minimal: /usr/bin/python2.6
python2.7-minimal: /usr/bin/python2.7
python3-minimal: /usr/bin/python3
python3.2-minimal: /usr/bin/python3.2
python3.2-minimal: /usr/bin/python3.2mu

And note that you can pull down packages directly from the archives without using apt-get(8). They're just HTTP sites and or will make it easy to grab the packages you need with wget(1) or curl(1).


Oh yes, note that /usr/lib/python* is where the Python libraries and modules are kept. /usr/bin/python* is where the Python interpreter is kept. Your attempt to fix things with cp /usr/lib/python2.7 /usr/bin/python2.7 didn't help. Also /usr/lib/python2.7 is a directory, but /usr/bin/python should be (and was) a single executable file. Feel free to rm -r /usr/bin/python2.7 /usr/bin/python.

share|improve this answer
By the way, rm has -i/--interactive option, you could use it too. – ulidtko Nov 15 '11 at 23:57
True, but rm -i gets old after four or five files. – sarnold Nov 15 '11 at 23:57
The method worked great and fixed my dkpg issue. Thank you! I also removed my old fix (cautiously btw :)) Now there is the problem of the python package: >>> numpy Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'numpy' is not defined I guess the PATH variable is wrong or something, cause dpkg tells me that numpy is installed. Do you know how I can have python in /usr/bin once again and also have the packages working? – Paul Nov 16 '11 at 1:05
If it helps: >>> print sys.path ['', '/usr/local/lib/', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux3', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages'] – Paul Nov 16 '11 at 1:06
@Paul: Are you just typing numpy at the prompt? Or import numpy at the prompt? You can't use plain numpy until you've imported the package. – sarnold Nov 16 '11 at 1:07

You must log in to answer this question.

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