3

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.

Shahriar49
  • 621
  • 1
  • 5
  • 18
  • It looks like maybe your preference is to install via pip(3), but out of curiosity, does it work if you install via conda (https://anaconda.org/conda-forge/earthengine-api)? If you don't use conda, or are not interested, no worries. – Justin Braaten Jun 06 '19 at 16:18
  • Thanks for reply, but I fixed it. – Shahriar49 Jun 07 '19 at 00:44
  • Try to work with x64 python but i am getting problems. Then I switch to the 32 bit version. and I don't generate any problem. check the version and architecture of the python – rral May 03 '20 at 03:08

2 Answers2

4

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
S. Bloch
  • 123
  • 1
  • 9
1

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.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108