On Mac OS X, it can be a little tricky to install matplotlib. This guide shows how matplotlib can be installed for Lion and Mountain Lion, following these instructions. Mavericks (10.9.x) ships with an older version of matplotlib (version 1.1.1), and some features will not work with that version. It is recommended to upgrade to the latest version following the same steps.
1. Install Apple's Command Line Tools
On Mac OS X Lion / Mountain Lion
Install the Apple Command Line Tools for XCode, for example from here. A (free) developer account may be required to access the file.
On Mac OS X Mavericks
Open a Terminal window and type:
Then follow the instructions to install the command line tools.
2. Install XQuartz / X11
You can skip this step on Mac OS X Lion.
On Mountain Lion / Mavericks
Download the installer for XQuartz to get X11 and the necessary libraries. This is only required for Mountain Lion or later versions of OS X, because Lion ships with X11.
3. Link Libraries
Run the following commands on your terminal shell:
sudo mkdir -p /usr/local/include sudo ln -s /usr/X11/include/freetype2/freetype /usr/local/include/freetype sudo ln -s /usr/X11/include/ft2build.h /usr/local/include/ft2build.h sudo ln -s /usr/X11/include/png.h /usr/local/include/png.h sudo ln -s /usr/X11/include/pngconf.h /usr/local/include/pngconf.h sudo ln -s /usr/X11/include/pnglibconf.h /usr/local/include/pnglibconf.h sudo mkdir -p /usr/local/lib sudo ln -s /usr/X11/lib/libfreetype.dylib /usr/local/lib/libfreetype.dylib sudo ln -s /usr/X11/lib/libpng.dylib /usr/local/lib/libpng.dylib
This will link the necessary files to where matplotlib expects them to be.
4. Install pip (with easy_install)
This step is only required if pip is not installed yet.
sudo easy_install pip
5. Install / Upgrade matplotlib (with pip)
sudo pip install matplotlib
or if you already have an older version installed, run:
sudo pip install matplotlib --upgrade
To confirm that everything worked, run
python -c 'import matplotlib; print matplotlib.__version__'
and confirm that you have at least version 1.3.1 or higher.