ModuleNotFoundError: No module named 'google.appengine'
Asked Answered
G

2

22

I want to do a google search in python3 on windows. The google instructions say they support python3 and to type "gcloud topic init" for details - but that fails saying no interpreter for python2.7. Do I have to install python2.7 to find out how to get it working on python3?

On python3 I get an error message as below. I have set up an API key and a Custom search engine. I did "pip install google-api-python-client". I downloaded and ran GoogleCloudSDKInstaller. This is the error:

from googleapiclient.discovery import build
service = build("customsearch", "v1", developerKey="xxxxxx")

I get:

[googleapiclient.discovery_cache:WARNING]:file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth (__init__.py:44, time=Apr-07 17:25) Traceback (most recent call last):   File "C:\Users\simon\Anaconda3\lib\site-packages\googleapiclient\discovery_cache\__init__.py", line 36, in autodetect
    from google.appengine.api import memcache ModuleNotFoundError: No module named 'google.appengine'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "C:\Users\simon\Anaconda3\lib\site-packages\googleapiclient\discovery_cache\file_cache.py", line 33, in <module>
    from oauth2client.contrib.locked_file import LockedFile ModuleNotFoundError: No module named 'oauth2client'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "C:\Users\simon\Anaconda3\lib\site-packages\googleapiclient\discovery_cache\file_cache.py", line 37, in <module>
    from oauth2client.locked_file import LockedFile ModuleNotFoundError: No module named 'oauth2client'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "C:\Users\simon\Anaconda3\lib\site-packages\googleapiclient\discovery_cache\__init__.py", line 41, in autodetect
    from . import file_cache   File "C:\Users\simon\Anaconda3\lib\site-packages\googleapiclient\discovery_cache\file_cache.py", line 41, in <module>
    'file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth') ImportError: file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth [googleapiclient.discovery:INFO]:URL being requested: GET https://www.googleapis.com/discovery/v1/apis/customsearch/v1/rest?key=AIzaSyBGDtIo_P8xXbn0ksb15wUhy6sdR_eBDpU
Glynda answered 7/4, 2019 at 16:41 Comment(0)
G
37

Needs the parameter cache_discovery=False when creating service, like follows:

service = discovery.build('customsearch', 'v1', credentials=<...>, cache_discovery=False)
Glynda answered 7/4, 2019 at 17:4 Comment(2)
Would be great to know why? Just following the quickstart guide results in errors for mePyromagnetic
@Rob, I was digging out the same problem and it seems that there is a broken code path in the cache system. You can see in these issues more information, but seems that the cache doesn't works properly with oauth2client > 4.0.0Hemicellulose
N
1

Although it arrives looking like a cascading error, when looking closely at the first line, this is in fact only a warning:

[googleapiclient.discovery_cache:WARNING]:file_cache is unavailable...

As such, if you don't have access to the instantiation, you can suppress it like this:

import logging

logging.getLogger('googleapiclient.discovery_cache').setLevel(logging.ERROR)

You will still get any actual errors.

With thanks to theacodes who gave that answer here

See also the discussion here

Nickey answered 1/6, 2020 at 6:10 Comment(1)
Note: the answer I refer to on github has a missing 'n' in 'client'.Nickey

© 2022 - 2024 — McMap. All rights reserved.