Python Installation - Datalab on GCP


Datalab Docker containers can be deployed on Google Cloud platform either from a local computer using the gcloud command line tool or from a web browser using Google Cloud Shell.

Creating a Custom Datalab Container

To install a Datalab container that includes the Earth Engine Python API, follow the instructions on the Cloud Datalab Quickstart page with the following exception:

  • Replace the standard datalab create command with the following one that uses a custom container image:
    export INSTANCE_NAME=datalab-ee-vm-${USER//_/}
    datalab create --image-name $CONTAINER_IMAGE_NAME $INSTANCE_NAME
    set ""
    set "INSTANCE_NAME=datalab-ee-vm"
    datalab create --image-name %CONTAINER_IMAGE_NAME% %INSTANCE_NAME%
    Note that the datalab create statement takes ~5 minutes to run. During this time GCP is setting up a virtual machine that contains Docker, creating a Datalab container, and propagating an SSH key that allows you connect securely. Make good use of this downtime by hydrating yourself. When the container is ready, you should see a message that says:

    The connection to Datalab is now open and will remain until this command is killed.

Authenticating to Earth Engine

In order to successfully run code in Datalab that accesses Earth Engine, you first need to authenticate to Earth Engine. To authenticate from within Datalab, navigate to the /notebooks/docs-earthengine folder and open up the authorize_notebook_server.ipynb notebook. Follow the instructions within the notebook to create and store authentication credentials.

Note that your credentials will persist if you stop your instance, but they will be removed if you delete and recreate your instance which will require you to re-authenticate.

Cleaning up

To avoid incurring charges to your Google Cloud Platform account for the resources used, make sure to do the following:

  1. Stop your instance when you are not actively using it. A virtual machine instance that is stopped will not incur charges, although resources that are attached to it may. See Billing for stopped instances for more details.
  2. Delete your instance and notebooks disk when you are done using it. Note that this will delete all files within the container, so make sure that you first download or transfer notebooks to an external code repository before deleting the notebook disk.