Closed 7yl4r closed 3 years ago
I tried running that code and this one https://notebook.community/tylere/docker-tmpnb-ee/notebooks/2%20-%20Earth%20Engine%20API%20Examples/0%20-%20Authenticate%20to%20Earth%20Engine, but there is the following error:
File "/tmp/ipykernel_100/2139424921.py", line 30 except urllib2.HTTPError, e: ^ SyntaxError: invalid syntax
This is a common error that you see when python 2 code is being run with a python 3 engine. In python 2 except urllib2.HTTPError, e:
means "catch this exception and create an variable with the name e for it. This syntax was deemed not very readable so it was changed. To change this to python 3 you would write except urllib2.HTTPError as e:
.
You should be able to make this minor fix and then run the code again. There may be other things in the code that need updating from python2 to python3 though.
There may be other things in the code that need updating from python2 to python3
for example: I just spotted this one: python2 allows print "hello"
without parentheses but python3 requires parentheses print("hello")
. So this line:
print '\nSuccessfully saved authorization to %s' % credentials_path
needs to be changed to
print('\nSuccessfully saved authorization to %s' % credentials_path)
I made some changes and most of this code is working, but haven't been able to access this folder config/earthengine/credentials
or something similar.
When I search the folder earthengine !find / -type d -name 'earthengine'
I see several paths with Permission denied
.
I see that the code uses urllib2
and this was not able to be installed by conda. This is because urllib2 is an older python2 library that has been replaced by urllib.request in python 3. The solution here is to convert the code from urllib2 to urllib.request. This is a good short summary.
Ideally google earth engine libraries should be installed using conda or pip. This is done by editing the environment.yml or requirements.txt files, respectively. Although some of the bash commands worked in the notebook on binder, the
earthengine authenticate
step did not. I think the solution here is one of:For (2) this example notebook appears to authorize using python code only: https://notebook.community/tylere/g4g14-ee-python-api/authorize_earth_engine_in_notebook
Do use caution here not to save any sensitive information to github. That include API auth tokens. I did not read through that in detail but sharing an API token on github could potentially give everyone access to your google account.