Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

running Ubuntu 12.04, I had the usual python 2.7 in place .

I needed python 2.6 , so I downloaded the source and did

sudo make install

A mistake, as I did not want to replace my system-wide python . Now some programs stopped working , e.g. update-manager with

ImportError: No module named gi.repository

I used update-alternatives to make python 2.7 default again, but many python applications still won't start up because of some missing modules .

Can someone give a hint what happened and what the best way to fix it would be?

Thanks in advance.

Edit :

I could get some functionality of apt-get to work by setting my own hard link from /etc/python to /etc/python2.7 . ( So I guess using update-alternatives really did not do much good eithe. ) I did a dist-upgrade , which basically worked, but a lot of the package managing via apt-get is still broken. In particular, a problem with python-minimal prevents many other installations of packages I wanted to do .

Setting up python-minimal (2.7.3-0ubuntu7) ...
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/local/lib/python2.7/", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/", line 16, in <module>
    import struct
  File "/usr/local/lib/python2.7/", line 1, in <module>
    from _struct import *
ImportError: No module named _struct
dpkg: error processing python-minimal (--configure):
 subprocess installed post-installation script returned error exit status 255

PS: Building 2.7 from source always did exit (also before dist-ugprade or update-alternatives) with

make: *** [libinstall] Error 1

Currently, on make , there are more issues (" Python build finished, but the necessary bits to build these modules were not found: _bsddb bsddb185 bz2
dl imageop sunaudiodev
To find the necessary bits, look in in detect_modules() for the module's name. ")

As this is a little over my head , I guess I am just better off with a fresh install from scratch .

share|improve this question

Your python 2.6 install has probably changed lots of settings and paths.

Your best bet is to reinstall the default python interpreter

sudo apt-get --reinstall install python python-support

I can't test it, but I hope that it works. Good luck.

If it doesn't work the only other idea that I have is to install python 2.7 from source, and afterwards trying to reinstall the default one again.

share|improve this answer
--reinstall sounded good but did not work , in fact due to a python error that came up in the process of running apt-get . Thanks anyways , though – zm0 Mar 19 '13 at 17:40
Edited the answer, try to complie 2.7 from source and re-do the reinstall vodoo. – Javier Rivera Mar 19 '13 at 18:06

I had a similar problem when I downgraded from debian/Testing to debian/Stable recently. I guess somewhere in the process, python modules got corrupted. Purging and reinstalling python was, as it was pointed out, a bit draconian. Thankfully, I came across the following

Following this suggestion, I tried the command

for pkg in `dpkg --get-selections | egrep -v 'deinstall' | egrep python | awk '{print $1}'`; do  apt-get -y --force-yes install --reinstall $pkg ; done

to reinstall anything that has python in its name, and that solved the problem.

share|improve this answer

My guess is that you accidentally got overwrote the default python directory (somehow) and 2.6 is incompatible with what update manager/apps need.

Try sudo apt-get purge python2 then sudo apt-get install python2. This should purge python from your system and reinstall it, making it the default Python again.

Only other idea is that you got a bad source for 2.6 and it as such made a bad install that wasn't bad enough to be detected by make???

share|improve this answer
Doing apt-get purge python will remove a LOT of packages and components which I would have to re-install manually after re-installing python (?) . Would like to keep that as a last resort only .. – zm0 Mar 19 '13 at 16:58
true. Though, if just reinstalling 2.7 via apt-get --reinstall install python2 python2-support doesn't work, it will be the best bet to go with. – RPi Awesomeness Mar 19 '13 at 17:01
Yes, --reinstall does not work . When purgeing, something went wrong, too . At the moment, I cannot use apt-get, because of (python) errors e.g. installing gtk components like checkbox , etc. I will now try to reset python - as this still seems to be the core of the problem - somehow manually. – zm0 Mar 19 '13 at 17:40

I ran into essentially the same issue, but for python-minimal 2.7.11-1.

cat /var/lib/dpkg/info/python-minimal.postinst

You should get something like this:

#! /bin/sh
set -e

python2.7 -m compileall /usr/share/python/ >/dev/null

Run the command without redirect to >/dev/null (edit the file, or: sudo python2.7 -m compileall /usr/share/python/). This will show you where post installation configuration is failing.


Listing /usr/share/python/penemue/lib/python2.7/site-packages/gevent 
Compiling /usr/share/python/penemue/lib/python2.7/site-packages/gevent/ ...
  File "/usr/share/python/penemue/lib/python2.7/site-packages/gevent/", line 183
    def makefile(self, mode="r", buffering=None, *,
SyntaxError: invalid syntax

In my case, it was a custom python package (built using dh-virtualenv) that lived under /usr/share/python. I had to run dpkg -P penemue and ultimately remove the /usr/share/python/penemue directory. I might have been able to just move the /usr/share/python/penemue directory out of the way.

Once I got rid of the bad code, running sudo apt-get install -f resolved the issues.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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