15

I have deployed a python code in Google App Engine.In my code,tried to import firebase_admin,but it shows following error,

import firebase_admin
ImportError: No module named firebase_admin

hello.py

import firebase_admin
from firebase_admin import credentials
from firebase_admin import db

I tried simple python code using Terminal: hello.py

import firebase_admin
print firebase_admin

Output in terminal:

~/Desktop$ python hello.py
<module 'firebase_admin' from '/usr/local/lib/python2.7/dist-packages/firebase_admin/__init__.pyc'>
Ramprasad
  • 7,981
  • 20
  • 74
  • 135
  • 2
    Have you installed the package? `pip install firebase-admin` – Thomas Aug 07 '17 at 19:02
  • 1
    @ThomasMey Yes I installed sudo pip install firebase-admin...it successfully installed..but still this error occurs... – Ramprasad Aug 08 '17 at 04:45
  • @ThomasMey I am using PyCharm in my Linux...Is it any issue for install firebase-admin on local machine? – Ramprasad Aug 08 '17 at 09:23
  • I'm using neither Pycharm nor Linux so I can't tell, but I'd recommend to just try it: Open the console, run `python` and enter `import firebase_admin` or just one of the lines above. If it works, it's Pycharm's fault. – Thomas Aug 08 '17 at 09:26
  • @ThomasMey I have updated my question,have a look... – Ramprasad Aug 08 '17 at 09:51
  • Check this answer: https://stackoverflow.com/a/37316449/4026792 Your problem is that Pycharm doesn't use the local python iirc – Thomas Aug 08 '17 at 19:04
  • @ThomasMey In local Pycharm it is added properly,On AppEngine,it shows same error,No module named firebase_admin.Even on appengine,pip list shows firebase_admin – Ramprasad Aug 10 '17 at 13:12
  • 2
    Have you vendored the library into your App Engine app? https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#installing_a_third-party_library – Hiranya Jayathilaka Aug 10 '17 at 17:18
  • @hiranya-jayathilaka after vendored the library works fine – Ramprasad Aug 16 '17 at 17:13

8 Answers8

15

Install "firebase-admin" by pip3 install firebase-admin

ijas
  • 409
  • 5
  • 8
5

Firstly, confirming your package path of executing program.

enter image description here

Secondly, Perferences --> Project Interpreter ,Make sure the Package install correct path enter image description here

Anyway, you should use correct python which is installed the packageenter image description here

Yang MingHui
  • 380
  • 4
  • 14
1

For me the problem was that I installed using pip and not pip3.

After correctly installing firebase_admin I also included this on .zshrc:

export PATH="/opt/homebrew/opt/python@3.11/bin:$PATH" 
alias python=python3
alias pip=pip3

Bonus tip:

Check Python version on pyvenv.cfg file, make sure to update Python if necessary and set the latest version to default as described on the first line above. Make sure to replace @3.11 with your latest version.

mdeotti
  • 101
  • 2
  • 10
0

Per Hiranya Jayathilaka's comment, third party libraries must be vendored into Google App Engine applications.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
0

I was trying to connect cloud firestore through python-admin-sdk using Visual Studio Code which gave me same error

Working environment:

  1. Ubuntu 20.04
  2. Python 3.8.5
  3. firebase-admin 5.0.0
  4. Visual Studio Code

Resolution by re-installing PyLance extension in Visual Studio Code.

Nishant Patel
  • 1,334
  • 14
  • 22
0

After unsuccessfully trying all incarnations of pip to install firebase_admin, what worked for me was adding firebase_admin in the requirements.txt file then run pip install -r requirements.txt

For some reason beyond my understanding, firebase_admin appears to work when installed by referencing the requirements.txt file but not when running pip directly.

wandesky
  • 94
  • 1
  • 6
0

Had the same issue here! Solved it by updating from python 3.7.9 to 3.9.13 All good now!!!

-6

update your

firebase_admin

to the latest version . this will solve the issue . if nit rename

firebase.py

to some other name... Its working

just not use

firebase.py

as a name for your project and it will work

Gautam Kumar
  • 1,385
  • 14
  • 17
  • That error message is just because missing firebase_admin Python module. So, how do you "update it to the last version"? Also, nobody here is using `firebase.py` as Python script name. – T77 Feb 15 '23 at 16:31