Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uWSGI - ImportError: No module named google.oauth2.credentials #249

Closed
richard-to opened this issue Mar 29, 2018 · 4 comments
Closed

uWSGI - ImportError: No module named google.oauth2.credentials #249

richard-to opened this issue Mar 29, 2018 · 4 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@richard-to
Copy link

richard-to commented Mar 29, 2018

I am developing a Flask app that runs using uwsgi. I'm running into the following error ImportError: No module named google.oauth2.credentials.

When I run the Flask app using Flask's builtin dev server, the application runs without issues.

The problem seems to stem from how the google-auth module is installed. There's no __init__.py file in the google namespace folder in site-packages. I believe this is the intended behavior.

I'm aware that python3.3 has implicit namespace packaging via PEP-420.

What I'm confused about is how the implicit namespace packaging works in python2.7. Does the installation process via pip do something special to make import google.oauth2.credentials work?

I'm also confused about what is different when running python2.7 via uwsgi since the same import does not work.


I've also included the following barebones test to reproduce the error.

Relevant versions

  • python 2.7.14
  • pip 9.0.3
  • uwsgi 2.0.13
  • google-auth 1.4.1
    • Installed via pip (not using virtualenv)

test.ini

[uwsgi]
socket = 0.0.0.0:5001
plugins-dir = /usr/lib/uwsgi/
plugins = python
protocol = uwsgi
pythonpath = /usr/local/lib/python2.7/site-packages
callable = app
max-requests = 1000
master = True
lazy-apps = True
processes = 1

test.py

import google.oauth2.credentials

working command

python test.py

failing command

uwsgi --ini test.ini --wsgi-file test.py

failing result

When I run the above command, the program will fail due to the following ImportError.

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import google.oauth2.credentials
ImportError: No module named google.oauth2.credentials

Workaround

One way I got the google namespace import to work was by doing this:

import site
site.addsitedir('/usr/local/lib/python2.7/site-packages')

import google.oauth2.credentials

I wonder why site-packages is not already added when using uwsgi.

I got the hint to try site.addistedir from this answer: https://stackoverflow.com/a/15209116/177646

@richard-to richard-to changed the title uWSGI - ImportError: No module named google.oauth2.credentials uWSGI - ImportError: No module named google.oauth2.credentials Mar 29, 2018
@richard-to
Copy link
Author

I ended up solving my problem.

Turns out the problem was a uWSGI configuration error on my part. Since I'm not using virtualenv, I needed to set PYTHONHOME to the correct value, which is /usr/local in my case. In the uwsgi configuration, this can be specified via the home parameter.

Once the PYTHONHOME is correctly set, this allows the google_auth-1.4.1-py3.6-nspkg.pth file to be found.

Example:

[uwsgi]
socket = 0.0.0.0:5001
plugins-dir = /usr/lib/uwsgi/
plugins = python
protocol = uwsgi
home = /usr/local
pythonpath = /usr/local/lib/python2.7/site-packages
callable = app
max-requests = 1000
master = True
lazy-apps = True
processes = 1

@theacodes
Copy link
Contributor

Glad you got it figured out, @richard-to!

@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Apr 7, 2020
@MatthewR586
Copy link

from google.oauth2.credentials import Credentials
When I tried to get this, I got error that "No module named 'google'"
I already installed in windows system.

@parthea
Copy link
Contributor

parthea commented Jun 3, 2024

@MatthewR586, Please could you open a new issue here? Please also include the full stack trace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

5 participants