Installing and using Basemap with Julia

01 October 2018  

Julia, Python, Basemap  

Oceanography, Maps  

A quick post about an installation, something I never remember how to do but can be useful to others.

Update November 2019

Just run

using Conda
Conda.add("basemap")

discard the rest of the post and enjoy!

Download package

Get the most recent (and stable) version of Basemap, for example in the ~/Software/ directory:

wget https://github.com/matplotlib/basemap/archive/v1.1.0.zip
unzip basemap-1.1.0.zip

Install package

Create a directory where the installation will be performed, for example:

mkdir ~/Software/Geos

Go into the geos directory:

cd basemap-1.1.0/
cd geos-3.3.3/

and start the installation of Basemap:

export GEOS_DIR="~/Software/Geos"
./configure --prefix=$GEOS_DIR
make
make install

The make can take up to a few minutes to finish.

pip install

Now the tricky part: you need to localise the python and pip executables corresponding to your version of Julia to run the installation scripts.

Starting in the basemap-1.1.0 directory:

For Julia-0.6 I had:

~/.julia/v0.6/Conda/deps/usr/bin/pip install pyproj
~/.julia/v0.6/Conda/deps/usr/bin/python setup.py install

For Julia-1.0.0, I found 3 installed pip:

~/.julia/packages/Conda/m7vem/deps/usr/bin/pip
~/.julia/packages/Conda/hsaaN/deps/usr/bin/pip
~/.julia/packages/Conda/a196m/deps/usr/bin/pip

so I used the most recent one: ~/.julia/packages/Conda/hsaaN/deps/usr/bin/pip

~/.julia/packages/Conda/hsaaN/deps/usr/bin/pip install pyproj
~/.julia/packages/Conda/hsaaN/deps/usr/bin/python setup.py install

Build Julia package

Now everything is ready for the installation of the module in Julia:

For Julia-0.6:

ENV["PYTHON"]="~/.julia/v0.6/Conda/deps/usr/bin/python"
Pkg.build("PyCall")

For Julia-1.0.0:

ENV["PYTHON"]="~/.julia/packages/Conda/hsaaN/deps/usr/bin/python"

and then in the package REPL:

pkg> build PyCall

Use it

using PyPlot, PyCall
@pyimport mpl_toolkits.basemap as basemap

so now you should be able to use Basemap almost as in Python.
This gist provides several useful examples to get inspiration from.