2

I tried to install basemap within Datalab using pip:

%bash
pip install basemap

and got the error:

Downloading/unpacking basemap
Could not find any downloads that satisfy the requirement basemap
Cleaning up... No distributions at all found for basemap
Storing debug log for failure in /root/.pip/pip.log

How do I install extra packages on Datalab if they are not supported by pip?

Lak
  • 3,876
  • 20
  • 34

5 Answers5

4

Use apt-get install. In a cell of your notebook:

%bash
apt-get -y update
apt-get -y install python-mpltoolkits.basemap

Then, remember to restart your kernel (by Reset Session)

Lak
  • 3,876
  • 20
  • 34
1

Use the following code for this:

%%bash
pip install package_name
Hudson Taylor
  • 1,142
  • 2
  • 10
  • 30
1

You might need to first do

apt-get update

So it gets the updated list of packages.

Lak
  • 3,876
  • 20
  • 34
1

Basemap doesn't come with the google datalab out of the box.

Note: I use shorthand '!' to indicate a bash command, rather than '%bash' as the google documents usually do.

As of Feb 2019, this works on a fresh google datalab:

Step 1: Install Pre-requisites

  • !apt-get update && apt-get install -y --allow-unauthenticated build-essential libgeos-3.5.0 libgeos-c1v5 libgeos++-dev

  • !pip install pyproj pyshp

Step 2: Install the whole package

  • !pip install https://downloads.sourceforge.net/project/matplotlib/matplotlib-toolkits/basemap-1.0.7/basemap-1.0.7.tar.gz

Step 3: Check the package has been installed correctly

  • !pip freeze

Step 4: Import the module

  • from mpl_toolkits.basemap import Basemap

@Lak: You will need to update page 155 of your book - Data Science on the Google Cloud platform as the instructions there won't work; basemap is one of the more difficult packages to get working.

Zack
  • 101
  • 1
  • 5
0

The command suggested by Lak might have worked in the past but it's no longer the case: as of today (Aug 2017) Google Datalab instances reject the command listed here

%bash

echo 'Y' | apt-get install python-mpltoolkits.basemap

outputs the error message:

E: Unable to locate package python-mpltoolkits.basemap E: Couldn't find any package by regex 'python-mpltoolkits.basemap'

Execution from the shell (vs. notebook) outputs the same error.

After searching various sources I found a fix that worked for me: from the notebook in Datalab I added an update cmd before the actual install, like this:

%bash 

echo 'Y' | apt-get update

echo 'Y' | apt-get install python-mpltoolkits.basemap
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219