简体   繁体   中英

Google App engine Firebase import error

I am working on a project in which i want to use firebase in webapp2 python. I created the lib folder in root directory of the project for using the third party library. Then i imported the firebase admin and it is give following error,s on import. Please help me where i am doing the mistake, Thanks

Imports:

import firebase_admin
import google.auth.transport.requests
import google.oauth2.id_token
from firebase_admin import auth
from firebase_admin import credentials

Log:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "D:\Work\Bolt Reactor\Final Website Production\kompassera\Routes.py", line 5, in <module>
    from controllers import Home, Signup, Login, Profile, Listing, Classroom, Search, Enrollment, Firebase
  File "D:\Work\Bolt Reactor\Final Website Production\kompassera\controllers\Signup.py", line 5, in <module>
    import firebase_admin
  File "D:\Work\Bolt Reactor\Final Website Production\kompassera\lib\firebase_admin\__init__.py", line 22, in <module>
    from firebase_admin import credentials
  File "D:\Work\Bolt Reactor\Final Website Production\kompassera\lib\firebase_admin\credentials.py", line 20, in <module>
    import google.auth
ImportError: No module named auth

Explanation

import google.auth.transport.requests

above line will look for the Google package in pythons default directory in on every machine this behaviour can be different depending on where i is going to look for the installed packages.

Solution: make a lib directory on the root of your project and place the google package in this lib directory, then add ____inti____.py in this lib folder and amend your imports like this

import lib.firebase_admin
import lib.google.auth.transport.requests
import lib.google.oauth2.id_token
from lib.firebase_admin import auth
from lib.firebase_admin import credentials

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM