3

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

  • What did you try, and what error did you encounter? – Bob Smith Mar 03 '20 at 17:52
  • I tried the simple `import geoviews as gv` and got the error message: `ModuleNotFoundError: No module named 'geoviews'` – Haynes Stephens Mar 03 '20 at 21:48
  • And when I try to pip install geoviews I get this error message: `ERROR: Command errored out with exit status 1: /usr/bin/python3 /usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpp4b7gqpo Check the logs for full command output.` and not sure how to deal with this. – Haynes Stephens Mar 03 '20 at 21:49

2 Answers2

7

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

jakevdp
  • 77,104
  • 11
  • 125
  • 160
  • Thank you! That definitely answers my question, but I hit another block. I'm trying to reproduce the code from this link (https://geoviews.org/gallery/bokeh/xarray_image.html#bokeh-gallery-xarray-image) but my Colab Notebook crashes for reasons I don't understand. Is it possible to get this to work properly? – Haynes Stephens Mar 04 '20 at 19:56
0

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

sam_cocha
  • 13
  • 3