Yes, you could be running Earth Engine in Python too.

These are instructions for setting up the Python Earth Engine API. These instructions worked for me on my bootcamped Mac OSX 10.7.5 running the 64-bit version of anaconda and Python version 2.7.11. The first part of this documentation comes entirely from a help document developed by Tyler Erickson at Google for installing ee-python with. The second part cames directly from the Google Earth Engine User Guides. If you want more information feel free to get in touch!

There are basically four main parts to this workflow.

  1. Install conda and python
  2. Create an environment for the ee package to live in + install any dependencies
  3. Authenticate yourself
  4. Open a new notebook, test if it worked and enjoy

Installing the conda Package Manager

conda is a cross-platform application for installing software packages. Although it is not specific to installing Python packages, it is being adopted by the scientific Python community for it's ability to handle Python packages that have dependencies on shared libraries. conda is open source, and is available as part of the Anaconda Python distribution, managed by Continuum Analytics.

The easiest way to install conda, is to download and install the Anaconda Python Distribution available. Binary installers are available for various operating systems, and specific instructions/notes for each operating system are listed below.

If you don't want to install the full Anaconda distribution (which is about 350MB), there are alternative methods of installing conda: you can install the minimal conda installation (a.k.a. miniconda), install the conda package from PyPI, or to download and install from the source code.

Mac OSX

  1. Go to http://continuum.io/downloads and download the Python 2.7 Graphical Installer.
  2. Execute the Graphical Installer package, and follow the instructions. Note that you may encounter the following message: To proceed, first click on the "Install on a specific disk…" option, then click back on the "Install for me only".

After completing the process, Anaconda will be installed in your home directory (i.e. $HOME/anaconda).

Windows 7

  1. Go to http://continuum.io/downloads and download the Python 2.7 Graphical Installer for your platform (32 bit or 64 bit).
  2. Execute the Graphical Installer package, and follow the instructions.
  3. When asked where it should be installed, choose “Just me”. By default, Anaconda will be installed in C:\Users\\AppData\Local\Continuum\Anaconda.
  4. Go to your Start Menu > All Programs > Anaconda folder, and start the “Anaconda Command Prompt”.
  5. List the system path

     echo %PATH%
    

    If the system path does not start with a path that includes the Anaconda installation location, see the troubleshooting section below.

     https://github.com/ContinuumIO/anaconda-issues/issues/41

Linux

  1. Go to http://continuum.io/downloads and download the Python 2.7 Installer.
  2. Follow the instructions for executing the installer. Note that you should not need administrative (sudo) privileges.

During the installation process your shell configuration file (such as ~/.bash_profile or ~/.bashrc) may be altered so that the Anaconda tools are added to your system path (i.e. by prepending the Anaconda bin directory to the PATH environmental variable). This will cause the version of Python packaged with Anaconda to become your default Python version.

#added by Anaconda 2.0.1 installer
export PATH="/home/johnsmith/anaconda/bin:$PATH"

If you do not want to add the Anaconda tools to your path by default, you instead create an alias that adds Anaconda to the path. For example, you can modify your shell configuration file as follows:

    #added by Anaconda 2.0.1 installer
    #export PATH="/home/johnsmith/anaconda/bin:$PATH"
    alias useconda='export PATH="$HOME/anaconda/bin:$PATH"; unset PYTHONPATH'

Then whenever you want to use Anaconda, just manually execute the aliased command by executing: useconda

By default all files are installed in a single folder your home directory (~/anaconda). To remove Anaconda, you can simply delete the directory.

Updating conda Once you have installed conda, run the following to command to update conda to the most recent version.

conda update conda

To check which version of conda you are running, execute the following command:

 conda --version

Creating a conda Environment for the Earth Engine API

This section illustrates how to build a conda environment that allows you to run Python scripts against the Earth Engine API. Note that these instructions were written using conda version 3.5.5.

  1. Create a new conda environment that includes Python 2.7.

     ENV_NAME=ee-python
     conda create -n ENV_NAME python=2.7
  2. A plan for downloading and linking packages will be presented, which you can review before proceeding. Once you proceed, a directory in your anaconda directory will be created.

  3. Next activate this environment:

     [OSX, Linux] source activate ENV_NAME
     [Windows] activate ENV_NAME 

Don't do this now, but once you are done using a conda environment, you can deactivate the environment by executing the following code:*

    [OSX, Linux] source deactivate
    [Windows] deactivate

  1. Install pycrypto into the conda environment. This package is used for OAuth2 authentication.

     conda install pycrypto
  2. Install cryptography, which includes cffi

     conda install -y cryptography
  3. Install PIP into the conda environment, so that it can be used to install Python packages that are not available as conda packages, but are available in the Python Package Index (PyPI).

     conda install -y pip
  4. Install the simplejson package -this wasn't in the original documentation.

     conda install simplejson
  5. Next install the Earth Engine Python API package.

     pip install earthengine-api
  6. Test that you can successfully import the Earth Engine API package, by running:

     python -c "import ee; print ee.__version__"

*Note for Windows users: Make sure that you execute this command in a directory that does not contains python.exe (such as the default Anaconda Command Prompt) , so that the python command correctly executes the python executable in the conda environment and has access to the Python packages that you have installed.

Setting Up Authentication Credentials

For setting up the authentication credentials, we following the documentation for setting up authentication credential straight from the current Google Earth Engine User Guides. I used my current developers account. The full directions can be found here:

https://developers.google.com/earth-engine/python_install

Here is the documentation copied directly from the website:

The Earth Engine APIs use the OAuth 2.0 protocol for authenticating clients. In order to authenticate, you will need to first setup a credentials file on your computer that authorizes access to Earth Engine on behalf of your Google account. You can trigger the process of creating the credentials file by calling the ee.Initialize() method from the following terminal command:

    python -c "import ee; ee.Initialize()"

If you call ee.Initialize() without any arguments (as the preceding command does), the API tries to read credentials from a file located in a subfolder of your home directory. The location of the credentials file depends on your operating system. On Linux or OSX, the location is

    $HOME/.config/earthengine/credentials

On Windows, the location is

    %UserProfile%\.config\earthengine\credentials

If a credentials file is not found, you will be presented with an error message that includes instructions for creating a new credentials file. The basic steps are:

  1. Open up a new terminal window, and copy the command that was presented in the error message into the new terminal window. This command runs a Python script (authenticate.py) that starts the process for creating a credentials file.
  2. The script (authenticate.py) attempts to open a web page (https://accounts.google.com/o/oauth2/auth). If you are not already signed in with your Google Account, you will be prompted to do so at this time. Once authenticated, the web page will ask you to authorize access to Earth Engine data.
  3. Click accept, and the web page will present you with an authorization code.
  4. Copy the authorization code, and paste in the terminal where the Python script (authenticate.py) is running. The script will write credentials file to the correct location on your file system.

Testing the installation

To test that authentication has been correctly setup, run the following script. I did this in Jupyter but I think you could do it in the shell to because all it does is print metadata from the image.

Import the Earth Engine Python Package

    import ee

Initialize the Earth Engine object, using the authentication credentials.

    ee.Initialize()

Print the information for an image asset.

    image = ee.Image('srtm90_v4')
    print(image.getInfo())

If everything is installed correctly, the metadata for an image should be printed.