Friday, January 6, 2012

Python matplotlib plotting setup for cygwin

Matplotlib is a popular python library for generating plot graphics.   It works with cygwin win32 but some non-intuitive steps are required.

Install cygwin:

CYGWIN_NT-5.1 1.7.9(0.237/5/3) 2011-03-29 10:10 i686 Cygwin
I am using cygwin with setup 2.7.3

Install python through cygwin:

This document describes installing python and matplot with cygwin.  For most windows users and cygwin users, normally you would use the external python executable.  I tend to prefer all of my script oriented applications running through cygwin including python.

Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin

In the cygwin setup.exe installer, install:

The freetype libs, python-gtk, python-tk, libpng

Download matplotlib from sourceforge:

I am using the latest version matplotlib-1.1.0 as of 1/2012.

Issues with standard python install and cygwin:

The typical 'python install' will not work with cygwin.  You need to modify a configuration file and run some other additional commands.

In the root directory of the expanded matplotlib directory, edit the setup.cfg.template configuration file.

Around line 70 in the file is a commented line, uncomment the line such that you have:

tkagg = False

Run install and watch it fail

Try running 'python install'

It should fail with an error like the following:

2 [main] python 2796 C:\cygwin\bin\python.exe: *** fatal error - unable to remap C:\cygwin\bin\cyggfortran-3.dll to same address as parent: 0x18660000 != 0x69780000
Stack trace:


Exit cygwin and close all cygwin instances including the one you are working with.  You won't be using the typical  cygwin prompt for the next command.

In windows explorer, open the cmd.exe or windows command

You will need to run rebaseall.  First, shut down any long running processes like sshd, close all Cygwin prompts and so on.

Type the following commands:

cd \cygwin\bin
PATH=. rebaseall -v

And you should get several lines of output.

Run install and watch it succeed

Try running 'python install' command again in the matplotlib directory

Running Example Program:

# python
Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
import matplotlib.pyplot as pyplot

About Me (Berlin Brown resume):

1 comment:

Brion Finlay said...

Thanks for the instructions, they were a great help.

Some points where I tripped up:

Install python through cygwin:

install gcc

It almost goes without saying, but I had a fresh cygwin install without gcc installed

Download matplotlib from sourceforge:

download and extract the tarball

Manually download the tarball, not the windows exe or the mac os-x egg. Before reading this post, the first time I ran easy_install it pulled the win32 executable and expanded it.

Issues with standard python install and cygwin:

copy setup.cfg.template to setup.cfg

otherwise the setting will not be picked up from setup.cfg.template and the build error for tkagg will show