python-2.7google-app-enginegoogle-oauthsix

Import six module not working despite pip installation


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


Solution

  • 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