Installation Wiki

Installing Matplotlib

From InstallationWiki

Jump to: navigation, search
Installing Matplotlib
Official Page
Project Documentation
Download
Source Book
200px-1847197906.jpg
ISBN 978-1-847197-90-0
Publisher Packt Publishing
Author(s) Sandro Tosi

Contents

[edit] Installing Matplotlib

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).

[edit] Installing Matplotlib on Linux

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)

python-matplotlib Synaptic (graphical)
apt-get or aptitude (command line)
Fedora python-matplotlib PackageKit (graphical)
yum or rpm (command line)
openSUSE python-matplotlib YaST (graphical)
zipper or rpm (command line)

[edit] Installing Matplotlib on Windows

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).

[edit] Installing Matplotlib on Mac OS X

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)

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/.

[edit] Installing Matplotlib using packaged Python distributions

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:

  • Python(x,y): This package is available for Windows and Ubuntu at

http://www.pythonxy.com/.

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.

[edit] Installing Matplotlib from source code

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.

[edit] Testing our installation

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

[edit] Source

The source of this content is Chapter 1: Installing Matplotlib of Matplotlib for Python Developers by Sandro Tosi (Packt Publishing, 2009).

Personal tools