Python 导入错误:没有名为 apiclient.discovery 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18267749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: No module named apiclient.discovery
提问by Huy Tower
I got this error in Google App Engine's Pythonhave used Google Translate API, But I don't know how to fix,
我在Google App Engine 的 Python 中遇到此错误已使用 Google Translate API,但我不知道如何解决,
<module>
from apiclient.discovery import build
ImportError: No module named apiclient.discovery
I'll try to set environment which indicates to Google App Engine SDK, And upload to Google Apps Engine again, always get the error,
我会尝试设置向 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.
错误:服务器错误
服务器遇到错误,无法完成您的请求。如果问题仍然存在,请报告您的问题并提及此错误消息和导致该问题的查询。
Please tell me how to fix,
请告诉我如何修复,
Thanks
谢谢
UPDATE : FixedFollow Nijjin's help, I fixed problems by adding the following folders,
更新:修复了跟随 Nijjin 的帮助,我通过添加以下文件夹修复了问题,
apiclient, gflags, httplib2, oauth2client, uritemplate
apiclient, gflags, httplib2, oauth2client, uritemplate
If you still got problem, please consider below Answer of this page to get more info. ex. : Varum answer, etc ...
如果您仍然遇到问题,请考虑本页面的以下答案以获取更多信息。前任。: Varum 回答等...
采纳答案by Jorvis
You should be able to get these dependencies with this simple install:
您应该能够通过这个简单的安装获得这些依赖项:
sudo pip install --upgrade google-api-python-client
This is described on the quick start page for python.
回答by Nijin Narayanan
apiclient
is not in the list of third party library supplied by the appengine runtime: http://developers.google.com/appengine/docs/python/tools/libraries27.
apiclient
不在 appengine 运行时提供的第三方库列表中:http: //developers.google.com/appengine/docs/python/tools/libraries27。
You need to copy apiclient
into your project directory & you need to copy these uritemplate
& httplib2
too.
你需要复制apiclient
到你的项目目录和你需要复制这些uritemplate
与httplib2
过。
Note: Any third party library that are not supplied in the documentation list must copy to your appengine project directory
注意:文档列表中未提供的任何第三方库都必须复制到您的 appengine 项目目录
回答by Joe Gregorio
There is a download for the Google API Python Client library that contains the library and all of its dependencies, named something like google-api-python-client-gae-<version>.zipin the downloads section of the project. Just unzip this into your App Engine project.
有一个包含库及其所有依赖项的 Google API Python 客户端库的下载,在项目的下载部分中命名为google-api-python-client-gae-<version>.zip。只需将其解压缩到您的 App Engine 项目中即可。
回答by Jesse Webb
apiclient
was the original name of the library.
At some point, it was switched over to be googleapiclient
.
apiclient
是图书馆的原名。
在某些时候,它被切换为googleapiclient
.
If your code is running on Google App Engine, both should work.
如果您的代码在 Google App Engine 上运行,则两者都应该可以工作。
If you are running the application yourself, with the google-api-python-clientinstalled, both should work as well.
如果您自己运行应用程序,并且安装了google-api-python-client,那么两者都应该可以正常工作。
Although, if we take a look at the source code of the apiclient
package's __init__.py
module, we can see that the apiclient
module was simply kept around for backwards-compatibility.
虽然,如果我们查看包的module的源代码apiclient
__init__.py
,我们可以看到该apiclient
模块只是为了向后兼容而保留的。
Retain apiclient as an alias for googleapiclient.
保留 apiclient 作为 googleapiclient 的别名。
So, you really should be using googleapiclient
in your code, since the apiclient
alias was just maintained as to not break legacy code.
所以,你真的应该googleapiclient
在你的代码中使用,因为apiclient
别名只是为了不破坏遗留代码而维护的。
# bad
from apiclient.discovery import build
# good
from googleapiclient.discovery import build
回答by wizmer
I had the same problem because of a bug in the installation of the URITemplate module.
由于 URITemplate 模块安装中的错误,我遇到了同样的问题。
This solved the problem:
这解决了这个问题:
pip install --force-reinstall uritemplate.py
回答by Keith Holliday
Make sure you only have google-api-python-client
installed. If you have apiclient
installed, it will cause a collision. So, run the following:
确保你只google-api-python-client
安装了。如果已经apiclient
安装,会引起碰撞。因此,运行以下命令:
sudo pip uninstall apiclient
回答by mrmuggles
I fixed the problem by reinstalling the package with:
我通过重新安装包解决了这个问题:
pip install --force-reinstall google-api-python-client
回答by varun
回答by Dan
"google-api-python-client" requires:
“google-api-python-client”需要:
pip install uritemplate.py
to fix problem on GAE Development Server:
修复 GAE 开发服务器上的问题:
from googleapiclient.discovery import build
ImportError: No module named googleapiclient.discovery
回答by Rathna
I encountered the same issue. This worked:
我遇到了同样的问题。这有效:
>>> import pkg_resources
>>> pkg_resources.require("google-api-python-client")
[google-api-python-client 1.5.3 (c:\python27), uritemplate 0.6 (c:\python27\lib\site-packages\uritemplate-0.6-py2.7.egg), six 1.10.0 (c:\python27\lib\site-packages\six-1.10.0-py2.7.egg), oauth2client 3.0.0 (c:\python27\lib\site-packages\oauth2client-3.0.0-py2.7.egg), httplib2 0.9.2 (c:\python27\lib\site-packages\httplib2-0.9.2-py2.7.egg), simplejson 3.8.2 (c:\python27\lib\site-packages\simplejson-3.8.2-py2.7-win32.egg), six 1.10.0 (c:\python27\lib\site-packages\six-1.10.0-py2.7.egg), rsa 3.4.2 (c:\python27\lib\site-packages\rsa-3.4.2-py2.7.egg), pyasn1-modules 0.0.8 (c:\python27\lib\site-packages\pyasn1_modules-0.0.8-py2.7.egg), pyasn1 0.1.9 (c:\python27\lib\site-packages\pyasn1-0.1.9-py2.7.egg)]
>>> from apiclient.discovery import build
>>>