Google API Python客户端:“ from six.moves import zip ImportError:没有名为moves的模块”

时间:2019-01-20 12:37:58

标签: python python-2.7 google-app-engine google-sheets google-api

我正在尝试使用googleapiclient在我的Python 2.7代码中使用Google Sheets API,但出现以下错误:“ from six.moves import zip ImportError:没有名为“。”的模块移动。

我在Mac上使用的是Python 2.7.10。

我的程序是使用Webapp2构建的,并部署在Google AppEngine上并已连接到Google数据存储。

我正在使用Google的最佳实践来使用第三方库,使用requirements.txtlib/appengine_config.py,如下所述: https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#installing_a_third-party_library

我尝试将六个作为捆绑库列出为app.yaml

我尝试使用不同版本的sixgoogle-api-python-client

我尝试过这里提出的解决方案:

1)ImportError: No module named moves

2)Google App Engine: from six.moves import http_client no module named moves

注意事项:

我可以从Python外壳程序成功进行Google Sheets API调用。

我尝试了另一种笨拙的方法。从https://code.google.com/archive/p/google-api-python-client/downloads下载google-api-client-gae-1.2.zip并将其解压缩到我的根目录中。这就要求将apiclient而不是googleapiclient导入我的代码中,并且虽然可以轻松地导入six.moves,但是却丢了API Key错误。我相信如果我解决了上面的6.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 -

1 个答案:

答案 0 :(得分:0)

six模块是App Engine Python 2.7运行时中的built-in third party libraries之一。唯一可用的版本是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'

似乎您的six目录中可能有旧版本的lib,或者项目中有一个名为six.py的文件?