I'm trying to run a script within a Google datalab Jupyter notebook that requires basemap, but I can't install this package. Yelsayed has pointed out that the module requires several dependencies, but even after building these the module won't install.
Here are the dependencies that I believe need to be installed:
!pip install Cython
!apt-get update && apt-get install -y gcc
!pip install pyproj
!pip install GEOS
These install without event. Finally basemap itself which again Yelsayed has pointed out needs to be done with the following:
!pip install https://downloads.sourceforge.net/project/matplotlib/matplotlib-toolkits/basemap-1.0.7/basemap-1.0.7.tar.gz
This takes time to install and seems to show promise, but ultimately it gets to 99% installed and then outputs "killed":
Collecting https://downloads.sourceforge.net/project/matplotlib/matplotlib-toolkits/basemap-1.0.7/basemap-1.0.7.tar.gz
Downloading https://downloads.sourceforge.net/project/matplotlib/matplotlib-toolkits/basemap-1.0.7/basemap-1.0.7.tar.gz (129.7MB)
99% |############################### | 129.7MB 154kB/s eta 0:00:01Killed
The "Killed" at end seems to indicate it ultimately hasn't worked. It does this reliably, re-attempting the above call fails in the same way. In any case I gave importing the module a go, but still get the same error:
ImportError: No module named basemap
Why is this happening and how do you successfully install basemap in this environment?
It doesn't look like basemap
is hosted on PyPI due to size. Look at the install instructions on https://github.com/matplotlib/basemap.
You can just use their direct link for v1.0.7:
!pip install https://downloads.sourceforge.net/project/matplotlib/matplotlib-toolkits/basemap-1.0.7/basemap-1.0.7.tar.gz
EDIT
Here's some more breakdown of installing the prerequisites as well, run all the following in notebook cells:
Your best bet is to install it directly from apt
to avoid versioning issues. You can do:
%bash
apt-get update && apt-get install -y build-essential libgeos-3.4.2 libgeos-c1 libgeos++-dev
You then install the python dependencies, using pip easily:
%bash
pip install pyproj pyshp
Then you can install the basemap package using the link above:
%bash
!pip install https://downloads.sourceforge.net/project/matplotlib/matplotlib-toolkits/basemap-1.0.7/basemap-1.0.7.tar.gz
You can then import the basemap class:
from mpl_toolkits.basemap import Basemap