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

I'm new to Linux and am trying to set up Python / Django on my machine! I installed Python 3.3 from the source file and it was compiled into /usr/local/bin. Then I created a symbolic link between /usr/bin/python and /usr/local/bin/python3, so that whenever I invoke python from the command line it uses the latest version.

Now I am trying to install MySQL Python and I got the following output:

apt-get install python-mysqldb

Reading package lists... Done
Building dependency tree
Reading state information... Done
python-mysqldb is already the newest version.
The following extra packages will be installed:
  apt-listchanges python-apt
Suggested packages:
  python-glade2 python-gtk2 python-apt-dbg python-vte python-apt-doc
The following packages will be upgraded:
  apt-listchanges python-apt
2 upgraded, 0 newly installed, 0 to remove and 142 not upgraded.
3 not fully installed or removed.
Need to get 0 B/394 kB of archives.
After this operation, 250 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Traceback (most recent call last):
  File "/usr/bin/apt-listchanges", line 28, in <module>
    import apt_pkg
ImportError: No module named 'apt_pkg'

Any ideas on how to fix this? Or any tips on how to clean up this install (if this one is too broken)?

share|improve this question
up vote 3 down vote accepted

If you "replace" the default python installation you will probably break the system. There are many system tools that use python2.X and will fail when using python3. In your case, python3 doesn't have the apt_pkg module, so you get that error.

To solve this just remove the symlink created and link it to the default python2.X (in 12.10 it is python2.7):

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

If you want to make python3 the "default" interpreter i guess the best way without breaking anything is using virtualenv (more info here):

virtualenv -p /usr/bin/python3.3 <destination dir>
share|improve this answer
thanks for the info -- it's all working now! – user1881353 Dec 11 '12 at 1:16

Don't symlink /usr/bin/python to python3. It will break a large part of Ubuntu. Only things which are actually ported to Python 3.x will be able to run under python3.

share|improve this answer
yeah, that fixed it. thanks for the help! – user1881353 Dec 11 '12 at 1:17

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.