Install GeoViews on a Google Colaboratory Notebook

Viewed 752

Is it possible to install geoviews on a Google Colaboratory notebook so that I can use it to plot data from an Xarray Dataset?

2 Answers

Geoviews depends on cartopy, which has some additional requirements that aren't covered by pip. You can install them with apt, at which point the geoviews installation will work correctly:

!apt-get install libgeos++ libproj-dev
!pip install geoviews

After this, you can run a basic geoviews command:

import geoviews as gv
import geoviews.feature as gf

gv.extension('matplotlib')
gf.ocean

enter image description here

As newer versions of Cartopy seem to have trouble installing on Google Colab I find it best to specify a specific version of Cartopy before installing Geoviews. (0.18.0)

Also, Cartopy and Shapely (which is preinstalled on Google Colab) aren't friends... So uninstalling Shapely first and reinstalling it without binaries gives better Cartopy perfomance as well. (Make sure to ignore shapely deprecation warnings as well)

# Uninstall existing shapely
# We will re-install shapely in the next step by ignoring the binary
# wheels to make it compatible with other modules that depend on 
# GEOS, such as Cartopy (used here).
!pip uninstall --yes shapely

# To install cartopy in Colab using pip, we need to install the library 
# dependencies first.
!apt-get install -qq libgdal-dev libgeos-dev
!pip install shapely --no-binary shapely
!pip install cartopy==0.18.0

#Install geoviews
!pip install geoviews

#Ignore shapely deprecations warnings
import warnings
warnings.filterwarnings('ignore')

Check it out yourself in this notebook: https://colab.research.google.com/drive/1ZL6frd87sG4ErqGrI2mJZI9ix-FRMV62

Or check it out this working example of Geoviews in combination with Xarray in this notebook: https://colab.research.google.com/drive/1sI51h7l-ySoW2bLrU-K1LMm-TYNVBlif

Related