Update:

Python’s matplotlib package is an amazing resource, and the Basemap toolkit extends matplotlib’s capabilities to mapping applications. Installing these packages is straightforward using Ubuntu’s package management system, but these packages may not work for all maps you want to produce. In that case, it is good to know how to install each package from source.

Installing Basemap using Ubuntu’s standard packages

If you are running a newer version of Ubuntu, you may be able to get away with simply installing matplotlib and basemap through the standard repositories. This approach should work well enough to get you started, but if you notice some odd behavior with your maps you might need to go back and install both packages from source.

Install matplotlib from source

We start by installing dependencies. This is a 200-500MB download, depending on what you already have installed:

sudo apt-get build-dep python-matplotlib

Now install git, if you have not done so already:

sudo apt-get install git

Now we need to clone the git repository for matplotlib. You can do this in your home folder, or somewhere like /usr/local/ if that is where you normally install packages from source. Once we have a local matplotlib repository, we need to run the install script:

Install Basemap from source

First we need to download the source code. As of this writing, the newest version of Basemap is 1.0.5. Look for the newest version here, and click the folder. On the next page, you are looking for a file called basemap-1.x.x.tar.gz. This is the file you want to download. It is about 120MB, so again you will need a decent internet connection.

When the download is complete, open the archive and drag the basemap-1.x.x folder to your home folder, or /usr/local/, or wherever you keep your source code.

We will first install geos. From the basemap-1.x.x directory, we need to change into the geos directory and set the GEOS_DIR environment variable. These directions assume you are working from your home directory; if you are working in /usr/local/, you will probably need to change the GEOS_DIR to /usr/local/:

You can test if everything worked by running an example. From your basemap-1.x.x directory, change into the examples directory and run simpletest.py. Basemap is a large library, so the example script may take a while to run:

An example map produced from the Basemap toolkit. If you see this, things have installed correctly.

If you see a map similar to this, things have installed correctly. You can see some more examples if you like. There are a fair number of examples, so looking at all of them might take a while. But they are pretty interesting, so you might enjoy it:

basemap-1.x.x/examples $ python run_all.py

Now that we have basemap installed and working, we can move on to making our own simple map.