模块未找到错误:没有名为'google.appengine'的模块。

22

我想在Windows上用Python3进行谷歌搜索。谷歌的说明称他们支持Python3,并且要键入“gcloud topic init”以获取详细信息,但失败了,显示没有Python2.7的解释器。我是否需要安装Python2.7才能找出如何使其在Python3上正常工作?

在Python3中,我会收到以下错误消息。我已设置API密钥和自定义搜索引擎。我执行了“pip install google-api-python-client”。我下载并运行了GoogleCloudSDKInstaller。这是错误:

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

我理解为:

[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
2个回答

37

创建服务时需要添加参数 cache_discovery=False,如下所示:

service = discovery.build('customsearch', 'v1', credentials=<...>, cache_discovery=False)

6
想知道为什么会出现这种情况?我按照快速入门指南进行操作,但仍有错误。 - Rob
5
@Rob,我正在查找同样的问题,似乎缓存系统中存在一个损坏的代码路径。您可以在这些 问题中查看更多信息,但似乎缓存与oauth2client > 4.0.0无法正常工作。 - Checo R

1
尽管它看起来像一个级联错误,但仔细查看第一行,实际上只是一个警告:
[googleapiclient.discovery_cache:WARNING]:file_cache不可用...
因此,如果您没有访问实例化,则可以像这样抑制它:
import logging

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

你仍会获得任何实际的错误。

感谢theacodes这里给出了答案。

此外,还请参阅这里的讨论。


注意:我在Github上提到的答案中,“client”单词拼写错误,缺少一个“n”。 - scharfmn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接