Matplotlib and basemap on Debian

Some installation instructions.

Installation

You will need to install it from source. It requires matplotlib. If you try to use the Debian package of matplotlib, you will soon see it is too old for basemap. Here is an example of an error :

ImportError: No module named axes_grid1 

So we need to install it from source. The latest (1.2.1) does not compile with the following error :

src/file_compat.h:4:32: error: numpy/npy_3kcompat.h: No such file or directory
In file included from src/backend_agg.cpp:42:
src/file_compat.h: In function ‘int npy_PyFile_CloseFile(PyObject*)’:
src/file_compat.h:125: warning: deprecated conversion from string constant to ‘char*’
src/backend_agg.cpp: In member function ‘Py::Object RendererAgg::write_rgba(const Py::Tuple&)’:
src/backend_agg.cpp:2040: error: ‘npy_PyFile_OpenFile’ was not declared in this scope
src/backend_agg.cpp:2050: error: ‘npy_PyFile_Dup’ was not declared in this scope
src/backend_agg.cpp:2054: error: ‘npy_PyFile_DupClose’ was not declared in this scope
src/backend_agg.cpp:2064: error: ‘npy_PyFile_DupClose’ was not declared in this scope

Going back to the previous version (1.2.0) works as a charm.

Using it

If you try to plot something and display it with plt.show(), it is likely you will not see something. So you need to change the backend (see the documentation for more information).

Choosing the correct backend depends on what you have installed. In any case, you have to create a file named matplotlibrc in $HOME/.matplotlib . Then put the chosen backend. I use

backend      : Qt4Agg

If you chose to use GTK, you may have the following error :

ImportError: No module named _backend_gdk 

Then you have to reinstall matplotlib with GTK support. For that, copy setup.cfg.template to setup.cfg and uncomment the following :

gtk = True
gtkagg = True
backend = GTK

Finally, run the install again.