Problem importing a module (mpl_toolkits.basemap) in Python

So the issue is this: I'm attempting to learn how to plot maps with Python, using shapefiles. There are plenty of examples available on the internet, but just about all of them start with something like

from mpl_toolkits.basemap import Basemap

Which, when I attempt to input this into an IPython notebook, the Python console, or Pycharm, returns

ImportError: No module named 'mpl_toolkits.basemap'

To which the next response is, okay, time to sudo apt-get install python-mpltoolkits.basemap. That runs, returning:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-mpltoolkits.basemap is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.

I tried sudo apt-get remove python-mpltoolkits.basemap and then re-installing with apt-get, no joy.

How can I either get the system to recognize that the module exists, or to re-install it in such a way that it's recognizable to the Python interpreter?


Solution 1:

This article describes how to install basemap. And Here is the git repo, and here is a browser downloadable source code.

From the article, in short:
1) Download the source if apt-get install does not work out
2) install the source (super useful if installing to a virtual environment) by:

cd basemap-1.x.x
python setup.py install

Then here is also the doc, with installation guides and how to test if you have installed correctly. (just run from mpl_toolkits.basemap import Basemap in terminal).

It's important to note that if you're having issues with libgeos being detected, the doc suggests that you install the included libgeos source (3.3.3) separately first.

Solution 2:

f you're using Anaconda, it has a package for basemap:

conda install basemap

(It looks like pip doesn't have the package any more.)