Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 am trying to upgrade my python matplotlib but for some reason I can't get it to upgrade.

I originally installed matplotlib with: apt-get install python-matplotlib which was fine. However it defaulted to version 1.1

I then downloaded the 1.2 source from the website and then extracted the tar.gz and ran :

sudo python setup.py build
sudo python setup.py install

After all this I went into python2.7 idle and typed:

import matplotlib
print matplotlib.__version__

So it seems its not updating. How can I update matplotlib to 1.2 or greater?

share|improve this question
up vote 8 down vote accepted

This is probably an issue with your PYTHONPATH environment variable, or a lack of one. Using apt-get, matplotlib will be installed into the /usr directory prefix. So you'll find the whole package installed somewhere like /usr/lib/python2.7/site-packages/matplotlib.

You can confirm this with a command like: dpkg -L python-matplotlib.

When you separately downloaded the matplotlib source, built and installed it yourself using the above commands, you will have installed it into the /usr/local prefix. This is good, as your system libraries (in /usr prefix) are managed by dpkg, and you don't want to overwrite or interfere with those files, for fear of breaking another, depending package or leaving stray, unmanaged files lying around.

Now, you're probably using the system-installed python. It comes pre-installed on (all?) Linux distros, so why wouldn't you? But this is installed in /usr. Python's default module search path is constructed from the prefix in which it is installed. So, your system python (configured with --prefix=/usr) will by default only search for modules installed in /usr/lib/python2.7, completely overlooking those modules you manually installed in /usr/local/lib/python2.7.

So, to work around this, here are some possible solutions:-

  1. (Don't do this!) Build and install matplotlib with --prefix=/usr.

  2. Edit your PYTHONPATH to include /usr/local/lib/python2.7/site-packages This is a feasible solution when it's your own machine. You install packages there as root user, and edit ~/.bashrc or /etc/bash.bashrc to export the PYTHONPATH environment variable. It's a bit messy for a multi-user machine or server, as all these packages have to be upgraded manually by the root user, which might not always be convenient. Much better to leave it up to your system package manager.

  3. Use easy_install to install matplotlib (or any library on PyPi) somewhere the system Python will find it. In this instance, it would probably complain that you already have it installed, (so you should un-install it first, with apt-get).

    easy_install -m matplotlib

    PyPi is usually kept up to date with the latest Python package versions. You'll know why if you ever have to upload a package there (piece of p*ss), so this is a reliable method of getting up-to-date python packages. You'll need the distribute package installed - install it with apt-get.

  4. Install matplotlib 1.2 in to your user directory. You could later remove it when the repositories are updated to the version you require.

    python setup.py install --user

The latter method is my favourite method. I discovered it relatively recently, but it doesn't require editing any system or user-specific configuration files or environment variables, doesn't interfere with system packages, and doesn't need a sudo user to install.

This will install matplotlib into ~/.local/lib/python2.7 on Linux; into ~/Library/... on OS X and probably somewhere else on some other distros. Either way, this method is supported on all platforms and your user-specific modules will be loaded in preference to the system-wide ones.

Now go have fun with matplotlib. It's a great package!

P.S. Don't build packages as root user. I think it's bad practice to leave root owned files in user directories.

P.P.S. You can check where matplotlib (or any other python module) was loaded from within the Python interpreter. e.g.:-

>>> import matplotlib
>>> print matplotlib.__file__
share|improve this answer
Any idea why mine outputs '/usr/lib/pymodules/python2.7/matplotlib/__init__.pyc' ? I seems that all my modules aren't installed in site-packages which is where I would except them as well – Nick Feb 10 '13 at 20:01
Different distro's. I'm on Arch currently... Either way, /usr prefix should be reserved for packages installed by your system package manager. Manually installed packages should usually go in to either /usr/local or /opt. – Alex Leach Feb 10 '13 at 20:03
Btw, you can check your module search path, with python -c 'import sys; print "\n".join(sys.path)'. This probably includes /usr/lib/pymodules – Alex Leach Feb 10 '13 at 20:05
ok, great thanks. I will try that – Nick Feb 10 '13 at 20:06
Cool, glad you got that sorted. I'll add that -m flag to my answer, for future peoples ;) – Alex Leach Feb 10 '13 at 20:13

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.