首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从apiclient导入发现ImportError:没有名为apiclient的模块

从apiclient导入发现ImportError:没有名为apiclient的模块
EN

Stack Overflow用户
提问于 2020-07-11 00:07:12
回答 1查看 255关注 0票数 1

我正在运行我在windows 10中的github上找到的徒弟源代码,但当我查看Cmd控制台时,出现了这个错误。看起来好像的尖头不见了。我使用pip install安装了它,但是我得到了同样的错误。我也尝试过pip install --upgrade google-api-python-client,但仍然会遇到同样的错误。

代码语言:javascript
复制
Traceback (most recent call last):
  File "C:\Users\Gilbert\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "C:\Users\Gilbert\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 311, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "C:\Users\Gilbert\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "C:\Users\Gilbert\Documents\Projets\APPRTC\apprtc-master\src\app_engine\apprtc.py", line 23, in <module>
    import analytics
  File "C:\Users\Gilbert\Documents\Projets\APPRTC\apprtc-master\src\app_engine\analytics.py", line 14, in <module>
    import apiauth
  File "C:\Users\Gilbert\Documents\Projets\APPRTC\apprtc-master\src\app_engine\apiauth.py", line 12, in <module>
    from apiclient import discovery
ImportError: No module named apiclient
INFO     2020-07-11 00:59:21,395 module.py:865] default: "GET / HTTP/1.1" 500 -
ERROR    2020-07-10 23:59:21,443 wsgi.py:269]
Traceback (most recent call last):
  File "C:\Users\Gilbert\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "C:\Users\Gilbert\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 311, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "C:\Users\Gilbert\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "C:\Users\Gilbert\Documents\Projets\APPRTC\apprtc-master\src\app_engine\apprtc.py", line 23, in <module>
    import analytics
  File "C:\Users\Gilbert\Documents\Projets\APPRTC\apprtc-master\src\app_engine\analytics.py", line 14, in <module>
INFO     2020-07-11 00:59:21,443 module.py:865] default: "GET /favicon.ico HTTP/1.1" 500 -
    import apiauth
  File "C:\Users\Gilbert\Documents\Projets\APPRTC\apprtc-master\src\app_engine\apiauth.py", line 12, in <module>
    from apiclient import discovery
ImportError: No module named apiclient
EN

回答 1

Stack Overflow用户

发布于 2020-07-14 16:33:06

我认为您的示例代码已经过时了,使用App中的Google客户端导入发现服务的正确方法就像下面的代码片段。

代码语言:javascript
复制
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

# this will take the credentials that was defined by the command 'gcloud auth application-default login' on local environments, this is already defined on App Engine STD/Flex(no custom runtime) and Cloud functions.

credentials = GoogleCredentials.get_application_default()


# if you are using Cloud functions or App Engine (GAE) STD environment set
# cache_discovery=False, to avoid try to save cache on disk
# if this is not set, the application works fine but will thrown some warnings

service = discovery.build('cloudresourcemanager', 'v1', credentials=credentials, cache_discovery=False)

# this example is to use cloud resource manager, but you can change this for the service that you need
#disable warnings to avoid noise in the logs, this applies for GAE STD & Cloud functions

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

requirements.txt

代码语言:javascript
复制
google-api-python-client==1.9.3
oauth2client==4.1.3

在这个谷歌的回购您可以找到更新的示例

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62843837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档