问题:ImportError:没有名为apiclient.discovery的模块
我在Google App Engine的Python使用过Google Translate API时遇到此错误,但是我不知道如何解决,
<module>
from apiclient.discovery import build
ImportError: No module named apiclient.discovery
我将尝试设置指示Google App Engine SDK的环境,然后再次上传到Google Apps Engine,始终会收到错误消息,
错误:服务器错误
服务器遇到错误,无法完成您的请求。如果问题仍然存在,请报告您的问题并提及此错误消息以及引起该问题的查询。
请告诉我如何解决,
谢谢
更新:修复了在
Nijjin的帮助下,我通过添加以下文件夹修复了问题,
apiclient, gflags, httplib2, oauth2client, uritemplate
如果仍然有问题,请考虑在此页面的“答案”下获取更多信息。例如 :Varum答案等…
I got this error in Google App Engine’s Python have used Google Translate API,
But I don’t know how to fix,
<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,
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 : Fixed
Follow Nijjin’s help,
I fixed problems by adding the following folders,
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 …
回答 0
您可以通过以下简单安装获得这些依赖项:
sudo pip install --upgrade google-api-python-client
在python的快速入门页面上对此进行了描述。
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.
回答 1
apiclient
是图书馆的原始名称。
在某个时候,它已切换为googleapiclient
。
如果您的代码在Google App Engine上运行,则两者均应正常工作。
如果您自己运行该应用程序,并且安装了google-api-python-client,那么两者都应该也可以正常运行。
虽然,如果我们看一下软件包模块的源代码apiclient
__init__.py
,我们可以看到该apiclient
模块只是为了向后兼容而保留下来的。
保留apiclient作为googleapiclient的别名。
因此,您确实应该googleapiclient
在代码中使用,因为apiclient
别名只是为了不破坏原有代码而维护的。
# bad
from apiclient.discovery import build
# good
from googleapiclient.discovery import build
apiclient
was the original name of the library.
At some point, it was switched over to be googleapiclient
.
If your code is running on Google App Engine, both should work.
If you are running the application yourself, with the google-api-python-client installed, both should work as well.
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.
Retain apiclient as an alias for googleapiclient.
So, you really should be using googleapiclient
in your code, since the apiclient
alias was just maintained as to not break legacy code.
# bad
from apiclient.discovery import build
# good
from googleapiclient.discovery import build
回答 2
apiclient
is not in the list of third party library supplied by the appengine runtime: 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.
Note: Any third party library that are not supplied in the documentation list must copy to your appengine project directory
回答 3
如果上述解决方案都不适合您,请考虑您是否已通过Anaconda安装了python。如果是这种情况,则使用conda安装google API库可能会解决该问题。
跑:
python --version
如果你得到类似的东西
Python 3.6.4 :: Anaconda, Inc.
然后尝试:
conda install google-api-python-client
正如bgoodr在评论中指出的那样,您可能需要指定渠道(认为存储库)才能获取google API库。在编写本文时,这意味着运行命令:
conda install -c conda-forge google-api-python-client
在https://anaconda.org/conda-forge/google-api-python-client上查看更多
If none of the above solutions work for you, consider if you might have installed python through Anaconda. If this is the case then installing the google API library with conda might fix it.
Run:
python --version
If you get something like
Python 3.6.4 :: Anaconda, Inc.
Then try:
conda install google-api-python-client
As bgoodr has pointed out in a comment you might need to specify the channel (think repository) to get the google API library. At the time of writing this means running the command:
conda install -c conda-forge google-api-python-client
See more at https://anaconda.org/conda-forge/google-api-python-client
回答 4
确保只google-api-python-client
安装了。如果已apiclient
安装,将导致碰撞。因此,运行以下命令:
sudo pip uninstall apiclient
Make sure you only have google-api-python-client
installed. If you have apiclient
installed, it will cause a collision. So, run the following:
sudo pip uninstall apiclient
回答 5
对于App Engine项目,您必须通过输入本地安装lib
pip install -t lib google-api-python-client
在这里阅读更多
For app engine project you gotta install the lib locally by typing
pip install -t lib google-api-python-client
read more here
回答 6
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>.zip in the downloads section of the project. Just unzip this into your App Engine project.
回答 7
我通过以下方法重新安装了软件包,从而解决了该问题:
pip install --force-reinstall google-api-python-client
I fixed the problem by reinstalling the package with:
pip install --force-reinstall google-api-python-client
回答 8
对于python3这对我有用:
sudo pip3 install --upgrade google-api-python-client
for python3 this worked for me:
sudo pip3 install --upgrade google-api-python-client
回答 9
由于URITemplate模块安装中的错误,我遇到了同样的问题。
这样就解决了问题:
pip install --force-reinstall uritemplate.py
I had the same problem because of a bug in the installation of the URITemplate module.
This solved the problem:
pip install --force-reinstall uritemplate.py
回答 10
在处理从Google日历解析最近的日历事件的项目时,遇到了同样的错误。
使用pip进行标准安装对我不起作用,这是我获取所需软件包时所做的事情。
直接转到源,这里是google-api-python-client的链接,但是如果您需要其他语言,则应该不会有太大区别。
https://github.com/google/google-api-python-client
单击左上角附近的绿色“克隆或下载”按钮,并将其另存为zip文件。将zip移到您的项目文件夹中,然后将其解压缩。然后将其创建的文件夹中的所有文件切回到项目文件夹的根目录中。
是的,这确实会使您的工作空间混乱,但是许多编译器都有隐藏文件的方法。
完成此标准后
from googleapiclient import discovery
效果很好。
希望这可以帮助。
I got this same error when working on a project to parse recent calendar events from Google Calendar.
Using the standard install with pip did not work for me, here is what I did to get the packages I needed.
Go directly to the source, here is a link for the google-api-python-client, but if you need a different language it should not be too different.
https://github.com/google/google-api-python-client
Click on the green “Clone or Download” button near the top left and save it as a zip file. Move the zip to your project folder and extract it there. Then cut all the files from the folder it creates back into the root of your project folder.
Yes, this does clutter your work space, but many compilers have ways to hide files.
After doing this the standard
from googleapiclient import discovery
works great.
Hope this helps.
回答 11
“ google-api-python-client”要求:
pip install uritemplate.py
解决GAE开发服务器上的问题:
from googleapiclient.discovery import build
ImportError: No module named googleapiclient.discovery
“google-api-python-client” requires:
pip install uritemplate.py
to fix problem on GAE Development Server:
from googleapiclient.discovery import build
ImportError: No module named googleapiclient.discovery
回答 12
我遇到了同样的问题。这工作:
>>> 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
>>>
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
>>>
回答 13
它仅在我使用sudo时与我一起使用:
sudo pip install --upgrade google-api-python-client
It only worked with me when I used sudo:
sudo pip install --upgrade google-api-python-client
回答 14
I was getting the same error, even after following Google’s guide at https://developers.google.com/drive/api/v3/quickstart/python, then I realized I had to invoke like this:
python3 quickstart.py
Instead of:
python quickstart.py <-- WRONG
(Note the “3
“)
Worked flawlessly.
I’m using Ubuntu 18.04.4 LTS
.
回答 15
用这个
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
use this
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib