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.
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.
After completing the process, Anaconda will be installed in your home directory (i.e. $HOME/anaconda).
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
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
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.
Create a new conda environment that includes Python 2.7.
ENV_NAME=ee-python
conda create -n ENV_NAME python=2.7
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.
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
Install pycrypto into the conda environment. This package is used for OAuth2 authentication.
conda install pycrypto
Install cryptography, which includes cffi
conda install -y cryptography
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
Install the simplejson package -this wasn't in the original documentation.
conda install simplejson
Next install the Earth Engine Python API package.
pip install earthengine-api
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.
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:
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.