Copyright 2018 Google LLC.

SPDX-License-Identifier: Apache-2.0

Earth Engine Colab installation

This notebook demonstrates a simple installation of Earth Engine to a Colab notebook.

Colab setup

This notebook section installs the Earth Engine Python API on your Colab virtual machine (VM) and will need to be executed each time a new Colab notebook is created. Colab VMs are recycled after they are idle for a while.

Install Earth Engine

The Earth Engine Python API and command line tools can be installed using Python's pip package installation tool. The following notebook cell line is starts with ! to indicate that a shell command should be invoked.


In [0]:
!pip install earthengine-api

Authenticate to Earth Engine

In order to access Earth Engine, signup at signup.earthengine.google.com.

Once you have signed up and the Earth Engine package is installed, use the earthengine authenticate shell command to create and store authentication credentials on the Colab VM. These credentials are used by the Earth Engine Python API and command line tools to access Earth Engine servers.

You will need to follow the link to the permissions page and give this notebook access to your Earth Engine account. Once you have authorized access, paste the authorization code into the input box displayed in the cell output.


In [0]:
import ee

# Check if the server is authenticated. If not, display instructions that
# explain how to complete the process.
try:
  ee.Initialize()
except ee.EEException:
  !earthengine authenticate

Test the installation

Import the Earth Engine library and initialize it with the authorization token stored on the notebook VM. Also import a display widget and display a thumbnail image of an Earth Engine dataset.


In [0]:
import ee
from IPython.display import Image

# Initialize the Earth Engine module.
ee.Initialize()

# Display a thumbnail of a sample image asset.
Image(url=ee.Image('CGIAR/SRTM90_V4').getThumbUrl({'min': 0, 'max': 3000}))