我通过 dev_appserver 在本地运行标准应用程序引擎环境,无法消除以下错误:
导入错误:没有名为 google.auth 的模块
完整追溯(用
...
替换个人详细信息):
Traceback (most recent call last):
File "/Users/.../google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/.../google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Users/.../google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/Users/.../.../main.py", line 6, in <module>
from services.get_campaigns import get_campaigns
File "/Users/.../.../get_campaigns.py", line 3, in <module>
from googleads import adwords
File "/Users/.../.../lib/googleads/__init__.py", line 17, in <module>
from ad_manager import AdManagerClient
File "/Users/.../lib/googleads/ad_manager.py", line 28, in <module>
import googleads.common
File "/Users/.../lib/googleads/common.py", line 51, in <module>
import googleads.oauth2
File "/Users/.../lib/googleads/oauth2.py", line 28, in <module>
import google.auth.transport.requests
File "/Users/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime/sandbox.py", line 1154, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named google.auth
我确实安装了 google.auth,如
pip show google.auth
所示:
Name: google-auth
Version: 1.6.3
Summary: Google Authentication Library
Home-page: https://github.com/GoogleCloudPlatform/google-auth-library-python
Author: Google Cloud Platform
Author-email: [email protected]
License: Apache 2.0
Location: /Users/.../Library/Python/2.7/lib/python/site-packages
Requires: rsa, pyasn1-modules, cachetools, six
Required-by: googleads, google-auth-oauthlib, google-auth-httplib2, google-api-python-client
我已经升级了所有需要 google.auth 的模块 - googleads、google-auth-oauthlib、google-auth-httplib2、google-api-python-client - 但没有结果。
我不太确定下一步要采取什么措施来调试这个问题。这里有人能指出我正确的方向吗?
经过多次尝试和错误,我发现了错误:Python运行时版本问题。
在我的 app.yaml 文件中我指定了:
service: default
runtime: python27
api_version: 1
threadsafe: false
我将运行时间更改为:
runtime: python37
感谢@AlassaneNdiaye 在评论中为我指明了这个方向。
由于名称污染,我对“google.auth.exceptions”也有类似的问题。它给了我模块未找到错误。我没有使用 Earth Engine Library,而是使用 youtube-uploader。
上传者需要 google-api-python-client。我把它安装在一个环境中。当我收到错误时,我尝试手动导入 ipython 进行测试。即使当我使用表补全时 ipython 能够找到它,比如说 google.auth.exceptions,当我说
from google.auth.exceptions import *
时它就会抛出错误。
我能够做到import google
。当我在环境目录中搜索时,我发现我有多个 google 模块。一个来自 google-api-python-client,另一个来自 googleapis-common-protos。我不确定它来自哪里,但这两个“谷歌”在哪里制造麻烦。