[英]Google API Python Client: "from six.moves import zip ImportError: No module named moves"
I am trying to use the Google Sheets API in my Python 2.7 code using the googleapiclient but I get the following error: "from six.moves import zip ImportError: No module named moves ".我正在尝试使用 googleapiclient 在我的 Python 2.7 代码中使用 Google Sheets API,但我收到以下错误:“from Six.moves import zip ImportError: No module named move ”。
I am using Python 2.7.10 on Mac.我在 Mac 上使用 Python 2.7.10。
My programme is built using Webapp2, deployed on Google AppEngine and is connected to Google Datastore.我的程序是使用 Webapp2 构建的,部署在 Google AppEngine 上并连接到 Google Datastore。
I am using Google's best practice for using third party libraries, using requirements.txt
, lib/
and appengine_config.py
, described here: https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#installing_a_third-party_library我正在使用谷歌使用第三方库的最佳实践,使用
requirements.txt
、 lib/
和appengine_config.py
,描述如下: https : //cloud.google.com/appengine/docs/standard/python/tools/using-libraries -python-27#installing_a_third-party_library
I have tried listing six as a bundled library in my app.yaml
我曾尝试在
app.yaml
中将六个作为捆绑库列出
I have tried playing around with different versions of six
and google-api-python-client
我尝试过使用不同版本的
six
和google-api-python-client
I have tried the solutions suggest here:我已经尝试过这里建议的解决方案:
1) ImportError: No module named moves 1) 导入错误:没有名为移动的模块
2) Google App Engine: from six.moves import http_client no module named moves 2) Google App Engine: from Six.moves import http_client no module namedmoves
Things to note:注意事项:
I can make a successful Google Sheets API call from my Python shell.我可以从我的 Python shell 成功调用 Google Sheets API。
I tried a different, clunkier approach;我尝试了一种不同的、更笨拙的方法; downloading
google-api-client-gae-1.2.zip
from https://code.google.com/archive/p/google-api-python-client/downloads and unzipping it in my root directory.从https://code.google.com/archive/p/google-api-python-client/downloads下载
google-api-client-gae-1.2.zip
并将其解压缩到我的根目录中。 This required importing apiclient
into my code instead of googleapiclient
and whilst it did not have any trouble importing six.moves, it threw missing API Key errors.这需要将
apiclient
导入到我的代码中,而不是googleapiclient
,虽然导入 6.moves 没有任何问题,但它抛出了缺少 API 密钥的错误。 I believe these errors would not be an issue if I solve the six.moves import error above as I have a GOOGLE_APPLICATION_CREDENTIALS
environment variable set which the google_api_python_client
would pick up on.我相信如果我解决了上面的 Six.moves 导入错误,这些错误就不会成为问题,因为我有一个
GOOGLE_APPLICATION_CREDENTIALS
环境变量集, google_api_python_client
会接收到它。
My code:我的代码:
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']]
My pip freeze:我的点子冻结:
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
My full stack trace:我的完整堆栈跟踪:
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 -
The six
module is one of the built-in third party libraries in the App Engine Python 2.7 runtime. six
模块是 App Engine Python 2.7 运行时中的内置第三方库之一。 The only available version is 1.9.0
, but this version has the six.moves
submodule:唯一可用的版本是
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'
It seems like you might have an old version of six
in your lib
directory, or perhaps a file in your project named six.py
?看起来您的
lib
目录中可能有一个旧版本的six
,或者您的项目中可能有一个名为six.py
的文件?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.