1

I am building a web app (based on google app engine & python 2.7) and trying to import the six.move module. But although "six" is installed, it is not found when importing (note, I am not using frameworks yet like Django).

On my working environment (env), I ran:

| => pip show six
Name: six

Version: 1.11.0
Summary: Python 2 and 3 compatibility utilities
Home-page: http://pypi.python.org/pypi/six/
Author: Benjamin Peterson
Author-email: benjamin@python.org
License: MIT
Location: /path/to/file/DeployedProjects/goinpact/env/lib/python2.7/site-packages
Requires: 

The module that calls for this package is "id_token.py" from "google.oauth2"

So, when I run

from google.oauth2 import id_token 

and then load my web app, the import error log reads:

File "/path/to/file/DeployedProjects/goinpact/env/lib/python2.7/site-packages/google/oauth2/id_token.py", line 19, in <module>
from six.moves import http_client
ImportError: No module named six.moves 

The id_token.py module calls:

from six.moves import http_client

...causing the log import error above.

My understanding is that if on my environment (env), I can see that "six" is installed, I should have no problem importing this module from my app. Is this somehow not correct?

I must be missing something basic but can't understand what? Please help!

PS: Resources I have also attempted:

A) Even calling from my "main.py" file:

import six

results in the same ImportError.

B) ImportError: No module named six

C) Unresolved: Cannot install python six module

pablo-az
  • 437
  • 5
  • 15
  • I'd check whether the packages in lib are installing their own (possibly old) versions of `six`, then maybe specify the version you want in your vendor requirements file and reinstall your vendor packages. – snakecharmerb Jan 12 '18 at 10:26
  • 1
    If this is a standard env app try using the GAE-provided `six` lib by requesting it in the `libraries` section of your `app.yaml` file. See https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#using_a_built-in_third-party_library_bundled_with_the_runtime – Dan Cornilescu Jan 12 '18 at 15:50
  • Here's how I resolved this problem: https://stackoverflow.com/a/51616840/901444 – slashdottir Jul 31 '18 at 15:22

1 Answers1

0

When a Python virtual environment is activated, paths are rewritten to add {env}/lib/python2.7/. However, GAE isn't itself aware of virtual environments. So if you want six (or some other pure-Python library) to be available to your app, you'll need to arrange that yourself. Instructions on how to do this are in https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27

Dave W. Smith
  • 24,318
  • 4
  • 40
  • 46