Shahriar49
Shahriar49

Reputation: 683

Installing earth engine on Ubuntu

I want to install Earth Engine API on Python on Ubuntu 18.04. I have both Python 2.7 and Python 3.6 installed on my system, and I install Earth Engine using both pip and pip3 as instructed (installing google-api-python-client, oauth2client, and earthengine-api) without any problem. But I get errors on both 2.7 and 3.6:

On Python 2.7, "import ee" works but "ee.Initialize()" returns this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Initialize'

On Python 3.6, "import ee" doesn't work and return this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sshahhey/.local/lib/python3.6/site-packages/ee/__init__.py", line 1, in <module>
    from .main import main
  File "/home/sshahhey/.local/lib/python3.6/site-packages/ee/main.py", line 10, in <module>
    import StringIO
ModuleNotFoundError: No module named 'StringIO'

Any help? I am particularly interested in solving the problem for Python 3.

Upvotes: 3

Views: 2464

Answers (2)

S. Bloch
S. Bloch

Reputation: 133

Following up on Kevin's answer:

I had this same issue, but the state of my /usr/local/lib/python2.7/site-packages/ee looked the same as that of my coworker, whose Earth Engine API was working fine. The issue is that there are 2 pip packages which write to the same directory:

  • earthengine-api:
    • this is the package you want
    • writes the Earth Engine library to site-packages/ee
  • ee:
    • Unrelated to EE, just a wrapper for dd
    • writes a main.py and __init__.py to site-packages/ee

The only difference between our two setups was the order in which we installed those packages. For me, installing ee second overwrote the __init__.py file, which prevented the ee module from importing the library contents. The fix was to completely clear out the directory and related dist-info dir, and start over:

  1. rm -rf /usr/local/lib/python2.7/site-packages/ee
  2. rm -rf /usr/local/lib/python2.7/site-packages/earthengine_api-0.1.182.dist-info
  3. sudo pip install earthengine_api

Upvotes: 4

Kevin Reid
Kevin Reid

Reputation: 43872

It looks like your system has a Python package called ee which is not the Earth Engine API. I say this because the Python 3 traceback specifies a file named ee/main.py, which does not exist and never has. This would also explain why ee.Initialize() was not found in the other case.

I'd recommend going into /home/sshahhey/.local/lib/python3.6/site-packages/ee/ and browsing the code there to see what other package it might be. If it's not something you need, then you can just delete that ee/. If it is something you need for another purpose, you can use virtualenv to manage installations of conflicting libraries.

Upvotes: 1

Related Questions