5

I am setting up a new python environment (in Windows 10) for the google earth engine python API (version 0.1.331) following the instructions detailed here. I have also installed gcloud utilities as described here. Once I have installed gcloud and activated the ee environment (with earthengine-api installed), I am able to run gcloud commands from the command line. However, when I try and run earthengine authenticate, I get an error.

The error (I've replaced my actual user directory name):

Fetching credentials using gcloud
Traceback (most recent call last):
  File "C:\Users\my_user_name\Miniconda3\envs\ee\lib\site-packages\ee\oauth.py", line 291, in _load_app_default_credentials
    subprocess.run(command, check=True)
  File "C:\Users\my_user_name\Miniconda3\envs\ee\lib\subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\my_user_name\Miniconda3\envs\ee\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\my_user_name\Miniconda3\envs\ee\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\my_user_name\Miniconda3\envs\ee\Scripts\earthengine-script.py", line 9, in <module>
    sys.exit(main())
  File "C:\Users\my_user_name\Miniconda3\envs\ee\lib\site-packages\ee\cli\eecli.py", line 82, in main
    _run_command()
  File "C:\Users\my_user_name\Miniconda3\envs\ee\lib\site-packages\ee\cli\eecli.py", line 61, in _run_command
    dispatcher.run(args, config)
  File "C:\Users\my_user_name\Miniconda3\envs\ee\lib\site-packages\ee\cli\commands.py", line 355, in run
    self.command_dict[vars(args)[self.dest]].run(args, config)
  File "C:\Users\my_user_name\Miniconda3\envs\ee\lib\site-packages\ee\cli\commands.py", line 397, in run
    ee.Authenticate(**args_auth)
  File "C:\Users\my_user_name\Miniconda3\envs\ee\lib\site-packages\ee\__init__.py", line 104, in Authenticate
    return oauth.authenticate(authorization_code, quiet, code_verifier, auth_mode,
  File "C:\Users\my_user_name\Miniconda3\envs\ee\lib\site-packages\ee\oauth.py", line 392, in authenticate
    _load_app_default_credentials(auth_mode == 'gcloud', scopes, quiet)
  File "C:\Users\my_user_name\Miniconda3\envs\ee\lib\site-packages\ee\oauth.py", line 294, in _load_app_default_credentials
    raise Exception('gcloud command not found. ' + tip) from e
Exception: gcloud command not found. Please ensure that gcloud is installed.
More information: https://developers.google.com/earth-engine/guides/python_install

What I've tried:

  • I've search for solutions on the stackexchange site and the user google group but have not found this particular issue.
  • I initially thought there was an issue with running oauth.py, which, at line 291, runs gcloud auth application-default login. However, if I just run that command at the commandline, it successfully launches an authorization prompt in the browser. However, when I try and run ee.Initialize() in a python session, the result is an error: No such file or directory: 'C:\\Users\\my_user_name/.config/earthengine/credentials'
  • It appears that _winapi.CreateProcess is trying to find a file that doesn't exist, but I haven't been able to figure out how to identify what file it is looking for.
1
  • Tom, can you make these more directions more explicit please? When I run $ee_Initialize()$ I get the error: Error in py_call_impl(callable, dots$args, dots$keywords) : Exception: gcloud failed. Please check for any errors above and install gcloud if needed. I think you are describing the fix to my issue, but I'm not sure how to implement your solution. I'm unclear what you mean by: 3. "Check if gcloud can be accessed by..." How do I check that? 4. "Go to System Properties..." Do you mean just on my computer? in R? I can't seem to find an app called 'system properties' in windows. 5. "Enter the
    – Matt Clark
    Jun 29, 2023 at 9:09

3 Answers 3

7

I was able to solve this issue by rolling back to a previous version using conda install -c conda-forge earthengine-api=0.1.329. I also tested version 0.1.330 and the problem persisted so rolled back to an earlier version. Once the version was rolled back, I ran the authentication with earthengine authenticate and then updated back to the most recent api version (0.1.331). After the update, ee.Initialize() is still able to complete successfully.

2
  • 2
    This has been reported as a bug to Google: issuetracker.google.com/issues/259499125 An alternative solution is to use earthengine authenticate --auth_mode=notebook
    – nrp1000
    Nov 22, 2022 at 14:49
  • 1
    (downgrading works) I downgraded from earthengine-api 0.1.334 to earthengine-api 0.1.329 and it works fine now. MORE INFO: python 3.10.8 | earthengine-api 0.1.329 | Google Cloud SDK 413.0.0 | bq 2.0.84 | core 2023.01.06 | gcloud-crc32c 1.0.0 | gsutil 5.17 Jan 12, 2023 at 23:06
2

For post May 12 2023 Google Bug Fix

After the bug fix was pushed out by Google, the accepted answer to this question is no longer the correct answer, particularly if you are on Windows. Instead, if you get this error it is likely being caused by:

a) gcloud not installed

b) gcloud not being on the Windows environment path variable.

The solution is therefore (for Windows 10):

  1. Install the gcloud CLI: https://cloud.google.com/sdk/docs/install
  2. Run through the setup that the CLI gives you (logs into g-account etc).
  3. Check if gcloud can be accessed from your standard Windows cmd window, if not...
  4. Go to: System Properties > Advanced > Environment variables > Path > New
  5. Enter the full path to the now installed google-cloud-sdk\bin
  6. Restart computer
  7. Test gcloud access again, should work, if so, follow the normal steps on the GEE install help doc to finish authentication in the conda env.
0

Try the following steps:

  1. In the google cloud console, create a project and go to APIs and Services section then create a service account.
  2. Download the json key from the permission section and keep it in the home directory.
  3. Run these commands in the ipython of your command prompt to check if it working for :

-- service_account = 'YOUR SERVICE ACCOUNT EMAIL which ends with iam.gserviceaccount.com'

-- creds = ee.ServiceAccountCredentials(service_account, '/Path/to the/gcloudkey.json')

-- ee.Initialize(creds)

Now, it should be fine initializing the earthengine with gcloud.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.