5

Versions

  • Python : 2.7.14
  • six : 1.9.0 & 1.11.0(tried on both)
  • OS : mac(10.13.3) & ubuntu(16.04) [tried on both]

Error

from six.moves import http_client
ImportError: No module named moves

Description

In flask application which is running on google app engine while running it on local system using dev_appserver.py getting above error while importing from six.moves import http_client

What I have tried

After importing six have tried dir(six) which shows that moves is there in list but it's not able to import it which is very strange.

Output of six.__version__: 1.11.0

Output if dir(six)

['/opt/tribes-backend', '/opt/tribes-backend/lib1', '/usr/lib/google-cloud-sdk/platform/google_appengine', '/usr/lib/google-cloud-sdk/platform/google_appengine', '/usr/lib/python2.7', '/usr/lib/python2.7/lib-dynload', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/ssl-2.7.11', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/grpcio-1.0.0', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/six-1.9.0', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/protobuf-3.0.0', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/enum-0.9.23', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/futures-3.0.5', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/setuptools-36.6.0', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/protorpc-1.0', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/pytz-2017.2', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.3', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/webob-1.1.1', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/werkzeug-0.11.10', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/yaml-3.10', '/usr/local/lib/python2.7/dist-packages/enum', '/usr/lib/google-cloud-sdk/platform/google_appengine/lib/concurrent/concurrent', '/usr/local/lib/python2.7/dist-packages/concurrent', '/usr/local/lib/python2.7/dist-packages/google', '/usr/lib/google-cloud-sdk/platform/google_appengine/google'] ['BytesIO', 'Iterator', 'MAXSIZE', 'Module_six_moves_urllib', 'Module_six_moves_urllib_error', 'Module_six_moves_urllib_parse', 'Module_six_moves_urllib_request', 'Module_six_moves_urllib_response', 'Module_six_moves_urllib_robotparser', 'MovedAttribute', 'MovedModule', 'PY2', 'PY3', 'StringIO', '_LazyDescr', '_LazyModule', '_MovedItems', '_SixMetaPathImporter', 'author', 'builtins', 'doc', 'file', 'name', 'package', 'path', 'version', '_add_doc', '_assertCountEqual', '_assertRaisesRegex', '_assertRegex', '_func_closure', '_func_code', '_func_defaults', '_func_globals', '_import_module', '_importer', '_meth_func', '_meth_self', '_moved_attributes', '_print', '_urllib_error_moved_attributes', '_urllib_parse_moved_attributes', '_urllib_request_moved_attributes', '_urllib_response_moved_attributes', '_urllib_robotparser_moved_attributes', 'absolute_import', 'add_metaclass', 'add_move', 'advance_iterator', 'assertCountEqual', 'assertRaisesRegex', 'assertRegex', 'b', 'binary_type', 'byte2int', 'callable', 'class_types', 'create_bound_method', 'exec_', 'functools', 'get_function_closure', 'get_function_code', 'get_function_defaults', 'get_function_globals', 'get_method_function', 'get_method_self', 'get_unbound_function', 'indexbytes', 'int2byte', 'integer_types', 'iterbytes', 'iteritems', 'iterkeys', 'iterlists', 'itertools', 'itervalues', 'moves', 'next', 'operator', 'print_', 'python_2_unicode_compatible', 'raise_from', 'remove_move', 'reraise', 'string_types', 'sys', 'text_type', 'types', 'u', 'unichr', 'viewitems', 'viewkeys', 'viewvalues', 'with_metaclass', 'wraps'].

As it can be seen from above output moves inside six still giving error while importing it.

Spent a lot of time on this and no solution till now any help would be greatly appreciated here. :(

UPDATE1

Error stacktrace :-

 from google.cloud.datastore import helpers
 File "/opt/tribes-backend/denv/local/lib/python2.7/site-packages/google/cloud/datastore/helpers.py", line 27, in <module>
 from google.cloud._helpers import _datetime_to_pb_timestamp
 File "/opt/tribes-backend/denv/local/lib/python2.7/site-packages/google/cloud/_helpers.py", line 30, in <module>
 from six.moves import http_client
 ImportError: No module named moves
vinit payal
  • 1,201
  • 2
  • 13
  • 27

3 Answers3

4

For me the issue was resolved by following it on https://github.com/googleapis/python-ndb/issues/249

andrewsg commented 11 days ago:

I think we've identified an issue with devappserver related to the six library specifically. Could you please try a workaround? Add the line: import six; reload(six) to the top of your app, before NDB is loaded and let me know if that works.

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
BejoyM
  • 63
  • 8
3

Based on follow up with google support team have figured out that communicating with datastore using google-cloud-datastore is deprecated instead using ndb for communicating datastore is the way to go.

Updated documentation stating deprecation using client datastore library is documented here

Documentation to getting started with ndb client library in python is documented here

vinit payal
  • 1,201
  • 2
  • 13
  • 27
0

In some cases if you want to use some python pure libraries, like six, available in your applications you will need to use third-party libraries. Follow the instructions here, to add a third-party library, until the command pip install -t lib -r requirements.txt. In your requirements.txt file just add six==1.11.0. It solved the problem for me.

gr7
  • 492
  • 3
  • 11
  • Thanks @gonçalo-albino sorry forgot to put this in question but have already tried it with no luck :( – vinit payal Mar 12 '18 at 13:10
  • Have you tried using the GAE-provided six lib by requesting it in the libraries section of your app.yaml file, like is showed here: https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#using_a_built-in_third-party_library_bundled_with_the_runtime @vinitpayal – gr7 Mar 12 '18 at 13:24
  • yes @gonçalo-albino tried with it also and in fact tried with six1.9.0(as it was suggested at [here](https://cloud.google.com/appengine/docs/standard/python/tools/built-in-libraries-27)) and six1.11.0 both but none of them helped – vinit payal Mar 12 '18 at 13:29
  • After you add the library six to your app.yaml file are you getting the same error message? @vinitpayal – gr7 Mar 13 '18 at 15:55
  • Yes @gonçalo-albino – vinit payal Mar 15 '18 at 10:32
  • 1
    Have you tried to create a isolated python environment with virtualenv[http://docs.python-guide.org/en/latest/dev/virtualenvs/ ]? This way you can provide the exact package version that you need for your project. Try to create a virtualenv environment, activate it and then follow this documentation[https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#copying_a_third-party_library ] for copying a third-party library. – gr7 Mar 16 '18 at 15:30
  • Thanks for suggestion @gonçalo-albino but actually I am already in virtualenvironment – vinit payal Mar 23 '18 at 03:28
  • I'm in the Google Cloud Platform support team and I saw that you have filed a support ticket. May you share the information when you get the resolution for the issue? Thanks – gr7 Mar 27 '18 at 07:53
  • Have got a response from cloud support team saying `the app engine standard runtime uses ndb client library to access datastore. You can't use the Cloud Datastore client library with Python applications in app engine stnadard environment.` which actually solved my problem – vinit payal Mar 27 '18 at 08:02
  • 1
    @vinitpayal May I ask you to post the comment as an answer? – gr7 Mar 27 '18 at 09:50
  • Thanks @gonçalo-albino you were really helpful in the process of reaching to a solution – vinit payal Mar 28 '18 at 05:31