11

I'm locally running a standard app engine environment through dev_appserver and cannot get rid of the following error:

ImportError: No module named google.auth

Full traceback (replaced personal details with ...):

Traceback (most recent call last):
  File "/Users/.../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/.../google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Users/.../google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/Users/.../.../main.py", line 6, in <module>
    from services.get_campaigns import get_campaigns
  File "/Users/.../.../get_campaigns.py", line 3, in <module>
    from googleads import adwords
  File "/Users/.../.../lib/googleads/__init__.py", line 17, in <module>
    from ad_manager import AdManagerClient
  File "/Users/.../lib/googleads/ad_manager.py", line 28, in <module>
    import googleads.common
  File "/Users/.../lib/googleads/common.py", line 51, in <module>
    import googleads.oauth2
  File "/Users/.../lib/googleads/oauth2.py", line 28, in <module>
    import google.auth.transport.requests
  File "/Users/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime/sandbox.py", line 1154, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named google.auth

I do have google.auth installed, as pip show google.auth shows:

Name: google-auth
Version: 1.6.3
Summary: Google Authentication Library
Home-page: https://github.com/GoogleCloudPlatform/google-auth-library-python
Author: Google Cloud Platform
Author-email: jonwayne+google-auth@google.com
License: Apache 2.0
Location: /Users/.../Library/Python/2.7/lib/python/site-packages
Requires: rsa, pyasn1-modules, cachetools, six
Required-by: googleads, google-auth-oauthlib, google-auth-httplib2, google-api-python-client

I have already upgraded all modules that require google.auth - googleads, google-auth-oauthlib, google-auth-httplib2, google-api-python-client - but without results.

I'm not quite sure what next actions to take in order to debug this issue. Anyone here can point me in the right direction?

Stiño
  • 2,663
  • 7
  • 25
  • 47
  • Show us the complete error traceback, not just the error line. – John Gordon May 03 '19 at 19:22
  • 2
    Are you sure the default interpreter is used when you execute your script? You can find out using `import sys; print(sys.executable)`. If it's different from `which python`, then that's your issue – Alassane Ndiaye May 03 '19 at 19:25
  • @JohnGordon added the full traceback. – Stiño May 03 '19 at 19:33
  • @AlassaneNdiaye I currently can't log anything in my project (it fails immediately). Will see if there is another way to check this – Stiño May 03 '19 at 19:35
  • I had the same problem, and I solved it. you can see here: https://stackoverflow.com/a/56884902/8244338 – Israel Jul 04 '19 at 09:35

2 Answers2

2

Your google.auth is installed in the system's Python site packages, not in your app:

Location: /Users/.../Library/Python/2.7/lib/python/site-packages

You need to install your app's python dependencies inside your app instead - note the -t lib/ pip option in the Copying a third-party library procedure you should follow:

  1. Use pip (version 6 or later) with the -t <directory> flag to copy the libraries into the folder you created in the previous step. For example:

    pip install -t lib/ <library_name>
    
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
0

After much trial and error, I found the bug: A python runtime version issue.

In my app.yaml file I had specified:

service: default
runtime: python27
api_version: 1
threadsafe: false

There I changed runtime to:

runtime: python37

Thanks to @AlassaneNdiaye for pointing me in this direction in the comments.

Stiño
  • 2,663
  • 7
  • 25
  • 47
  • 1
    That moves you to the 2nd generation standard environment, where the [Private dependencies](https://cloud.google.com/appengine/docs/standard/python3/specifying-dependencies) applies. But you still need to install your dependencies in your app, otherwise it won't work when deployed on GAE. – Dan Cornilescu May 04 '19 at 09:33