Reputation: 43
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 ".
I am using Python 2.7.10 on Mac.
My programme is built using Webapp2, deployed on Google AppEngine and is connected to 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
I have tried listing six as a bundled library in my app.yaml
I have tried playing around with different versions of six
and google-api-python-client
I have tried the solutions suggest here:
1) ImportError: No module named moves
2) Google App Engine: from six.moves import http_client no module named moves
Things to note:
I can make a successful Google Sheets API call from my Python shell.
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. 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. 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.
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 -
Upvotes: 1
Views: 1552
Reputation: 21550
The six
module is one of the built-in third party libraries in the App Engine Python 2.7 runtime. The only available version is 1.9.0
, but this version has the six.moves
submodule:
$ 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
?
Upvotes: 0