There are several ways to install Matplotlib on our system:
Using packages from a Linux distribution
Using binary installers (for Windows and Mac OS X only)
Using packaged Python distributions that contain Matplotlib in the toolbox proposed
From the source code
We will look at each option in detail. We assume that Python, NumPy, and the optional build and runtime dependencies are already installed in the system (in order to install them, refer to their installation guides).
The advantage of using a Linux distribution is that several programs and libraries are already prepared by the distribution developers and made available (in a package format) to users. All we have to do is use the right tool and install the package.
In the following table, we will present some of the common Linux distributions package names for Matplotlib and the tools we can use to install the package:
Distribution |
Package name |
Installer tool |
---|---|---|
Debian or Ubuntu (and all other Debian derivatives) |
|
Synaptic (graphical) apt-get or aptitude (command line) |
Fedora |
|
PackageKit (graphical) yum or rpm (command line) |
openSUSE |
|
YaST (graphical) zipper or rpm (command line) |
Before we can install Matplotlib, we have to satisfy its main dependencies. So, we have to download:
Installers for Python, which are available in the DOWNLOAD section of http://www.python.org/
Installers for NumPy, which are available in the Download section of http://www.scipy.org/
Once we've got the above packages correctly installed, we can go to the main project page of Matplotlib on SourceForge at http://sourceforge.net/projects/matplotlib/. In the Files section, we can find the relative versions of the binary packages for the Python that we have just installed (2.4, 2.5, or 2.6).
The procedure to install Matplotlib correctly on Mac OS X is similar to that of Windows.
First of all, we need to download:
Installers for Python, which are available in the DOWNLOAD section of http://www.python.org/ (the one already available in Mac OS X fives problem when using Matplotlib)
Installers for NumPy, which are available in the Download section of http://www.scipy.org/ or can be retrieved directly from http://pythonmac.org/
At this point, once they are correctly installed, we can download the binary installer from the download area of Matplotlib SourceForce page at http://sourceforge.net/projects/matplotlib/ or we can retrieve the version available at http://pythonmac.org/.
There are some packaged distributions of Python that contain Matplotlib in them, along with many other tools, such as IPython, NumPy, SciPy, and so on. These distributions will set up all the necessary things we need so that we can use Matplotlib on our machine. Some of the distributions are as follows:
Enthought Python Distribution (EPD): This package is available for Windows, Mac OS X, and Red Hat. We can download it from http://www.enthought.com/products/epd.php.
Python(x,y): This package is available for Windows and Ubuntu at http://www.pythonxy.com/.
Sage: This package is available for Linux at http://www.sagemath.org/.
These are mainly scientific distributions that install a lot of tools we don't directly need or use, but they have the advantage of making it easy to get Python, NumPy, and Matplotlib installed and working on our system.
There are two ways of obtaining the Matplotlib source code. They are:
Downloading it from the source code tarballs available in the download area of Matplotlib SourceForge project page at http://sourceforge.net/projects/matplotlib/.
Retrieving it from the Subversion (SVN) repository. This is the place where development takes place, so use it only if you know what you're doing.
If we decided to go with SVN, we can follow the instructions available in the Develop section of http://sourceforge.net/projects/matplotlib/.
If we are going to use the source code tarball, we will have to unpack it, go into the created source directory, and execute the following commands:
$ python setup.py build
$ sudo python setup.py install
These commands will build and then install Matplotlib. We will need administrative privileges to install it into the system directories (hence the sudo
command in this Linux example).
Many aspects of the installation can be tuned using setup.cfg
, a file shipped with the source code and used at build and install time. We can use it to customize the build process, such as changing the default backend, or choosing whether to install the optional libraries or not.
If we want to install Matplotlib from source on Windows, the Files section of Matplotlib SourceForge page contains handy egg
files which we can download (choosing the Python version of interest) and then install using setuptools
command. The following command will install Matplotlib on your machine:
$ easy_install matplotlib-<version>-py<py version>-win32.egg
Egg
files are also available for Mac OS X, and we can use them in the same way as described above.
To ensure we have correctly installed Matplotlib and its dependencies, a very simple test can be carried out in the following manner:
$ python
Python 2.5.4 (r254:67916, Feb 18 2009, 03:00:47)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> print numpy.__version__
1.2.1
>>> import matplotlib
>>> print matplotlib.__version__
0.98.5.3
If there's no error while executing this, then we are done.