我尝试使用 googleapiclient 在我的 Python 2.7 代码中使用 Google Sheets API,但收到以下错误:“from Six.moves import zip 导入错误:没有名为“moves”的模块。
我在 Mac 上使用 Python 2.7.10。
我的程序是使用 Webapp2 构建的,部署在 Google AppEngine 上并连接到 Google 数据存储区。
我正在使用 Google 使用第三方库的最佳实践,即使用 requirements.txt
、lib/
和 appengine_config.py
,如下所述:
https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#installing_a_third-party_library
我尝试在我的 app.yaml
中列出六个作为捆绑库
我尝试过使用不同版本的 six
和 google-api-python-client
我已经尝试过这里建议的解决方案:
1) ImportError: No module named moves
2) Google App Engine: from six.moves import http_client no module named moves
注意事项:
我可以从 Python shell 成功调用 Google Sheets API。
我尝试了一种不同的、更笨拙的方法;从 https://code.google.com/archive/p/google-api-python-client/downloads 下载 google-api-client-gae-1.2.zip
并将其解压到我的根目录中。这需要将 apiclient
导入到我的代码中,而不是 googleapiclient
,虽然导入 6.moves 没有任何问题,但它引发了缺少 API key 的错误。我相信,如果我解决了上面的 Six.moves 导入错误,这些错误就不会成为问题,因为我有一个 GOOGLE_APPLICATION_CREDENTIALS
环境变量集,google_api_python_client
会接收到该变量。
我的代码:
from googleapiclient import discovery
class SpreadsheetProcessor:
def __init__(self, spreadsheet_id, range_):
service = discovery.build('sheets', 'v4')
request = service.spreadsheets().values().get(
spreadsheetId=spreadsheet_id, range=range_)
response = request.execute()
self.results = [value[0] for value in response['values']]
我的点卡住:
autopep8==1.4.3
cachetools==3.0.0
certifi==2018.11.29
chardet==3.0.4
enum34==1.1.6
fancycompleter==0.8
futures==3.2.0
google-api-core==1.7.0
google-api-python-client==1.7.7
google-auth==1.6.2
google-auth-httplib2==0.0.3
google-cloud-core==0.29.1
google-cloud-datastore==1.7.3
googleapis-common-protos==1.5.6
grpcio==1.18.0
httplib2==0.12.0
idna==2.8
linecache2==1.0.0
pdbpp==0.9.3
protobuf==3.6.1
pyasn1==0.4.5
pyasn1-modules==0.2.3
pycodestyle==2.4.0
Pygments==2.3.1
pyrepl==0.8.4
pytz==2018.9
requests==2.21.0
rsa==4.0
six==1.12.0
traceback2==1.4.0
uritemplate==3.0.0
uritemplate.py==3.0.2
urllib3==1.24.1
wmctrl==0.3
我的完整堆栈跟踪:
ERROR 2019-01-20 11:52:23,705 wsgi.py:263]
Traceback (most recent call last):
File "/Users/muzzialdean/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/muzzialdean/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Users/muzzialdean/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/Users/muzzialdean/Muzzi/tech-tests/ghostr/ghostr.py", line 3, in <module>
from models import Ghost, GhostDatabase
File "/Users/muzzialdean/Muzzi/tech-tests/ghostr/models.py", line 2, in <module>
from googleapiclient import discovery
File "/Users/muzzialdean/Muzzi/tech-tests/ghostr/lib/googleapiclient/discovery.py", line 21, in <module>
from six.moves import zip
ImportError: No module named moves
INFO 2019-01-20 11:52:23,715 module.py:861] default: "GET / HTTP/1.1" 500 -
最佳答案
6
模块是 built-in third party libraries 之一在 App Engine Python 2.7 运行时中。唯一可用的版本是 1.9.0
,但该版本具有 six.moves
子模块:
$ python
Python 2.7.14 (default, Sep 13 2018, 17:12:41)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from six.moves import zip
>>> import six
>>> six.__version__
'1.9.0'
您的 lib
目录中可能有旧版本的 six
,或者项目中可能有一个名为 six.py
的文件>?
关于python - 谷歌API Python客户端: "from six.moves import zip ImportError: No module named moves",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54276516/