importorror:没有名为apiclient.discovery的模块

2024-06-06 10:25:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Google App Engine的Python中得到了这个错误,Python使用了Google Translate API, 但我不知道怎么解决

<module>
from apiclient.discovery import build
ImportError: No module named apiclient.discovery

我将尝试设置环境,它向Google App Engine SDK指示, 然后再次上传到Google Apps Engine,总是会得到错误信息

Error: Server Error

The server encountered an error and could not complete your request. If the problem persists, please report your problem and mention this error message and the query that caused it.

请告诉我怎么修理

谢谢

更新:已修复 在倪进的帮助下, 我通过添加以下文件夹修复了问题

apiclient, gflags, httplib2, oauth2client, uritemplate


Tags: andtheapiappyour错误googleerror
3条回答

apiclient不在appengine运行时提供的第三方库列表中:http://developers.google.com/appengine/docs/python/tools/libraries27

您需要将apiclient复制到项目目录中,还需要复制这些uritemplate&;httplib2

注意:文档列表中未提供的任何第三方库都必须复制到appengine项目目录

apiclient是库的原始名称。
在某个时刻,它被转换为googleapiclient

如果你的代码在Google App Engine上运行,两者都应该可以工作。

如果您自己运行应用程序,并且安装了google-api-python-client,那么两者都应该可以正常工作。

尽管,如果我们看一下the source code of the ^{} package's ^{} module,我们可以看到apiclient模块只是为了向后兼容而保留的。

Retain apiclient as an alias for googleapiclient.

因此,您确实应该在代码中使用googleapiclient,因为apiclient别名的维护只是为了不破坏遗留代码。

# bad
from apiclient.discovery import build

# good
from googleapiclient.discovery import build

您应该能够通过这个简单的安装获得这些依赖项:

sudo pip install --upgrade google-api-python-client

这在quick start page for python上有描述。

相关问题 更多 >