Firebase Admin SDK with Flask throws error No module named firebase_admin

2024/10/7 18:29:11

--- Question closed

It was my mistake, my uWSGI startup script switches to a different virtualenv.

--- Original question

I'm trying to publish push notifications from my Flask app server to Android APP.

Server environment (dev):

  • Mac OS Sierra
  • Flask 1.0.2
  • Python 3.6.5
  • firebase-admin SDK 2.17.0 (the latest version)

When running code as Flask application for initialising the SDK, import statement throws error:

import firebase_admin

ModuleNotFoundError: No module named 'firebase_admin'

However, running above import statement from Python interpreter mode gives no error. PyCharm is also able to recognize the firebase_admin module. All three setups (Flask app, interpreter, PyCharm) use the same virtualenv.

I had tried few older versions of SDK but error persists. Any clue?

--- More details

The module was installed from command line within virtualenv using command pip install firebase-admin.

The error occurs when running the code as Flask+uWSGI app from command line, within the same virtualenv. pip freeze shows that the module is indeed present.

--- Question closed

It was my mistake, my uWSGI startup script switches to a different virtualenv.

Answer

How did you install/add the firebase_admin package to your project?

If you haven't explicitly installed/added the package, I've only come across a few cases (there may be other cases/solutions as well), that gives off the error ModuleNotFoundError: No module named 'firebase_admin':

PyCharm

If using PyCharm, you can install/add it from the PyCharm preferences

  • File > Preferences > Project > Project Interpreter
  • Click the add button, search for firebase, select the appropriate package: firebase-admin
  • Click "Install Package" button.

Visual Studio Code / Alternative installation

I use Visual Studio Code, and opted to install firebase_admin libraries into the virtualenv using a requirements.txt file saved in the root directory. You can still use this method even if you're using PyCharm:

1) Activate your environment

2) Create a requirements.txt file with the following contents:

firebase_admin
// other packages

3) Run pip install

pip install -r requirements.txt

4) After installing, you can confirm that's already available by checking the site-packages folder in the following directory:

env/lib/site-packages/firebase_admin
env/lib/site-packages/firebase_admin-<version>.dist-info

5) Try running the code again.

Hope that helps!

https://en.xdnf.cn/q/118791.html

Related Q&A

Recursive generator for change money - python

First, thanks for any help. I have this recursive code for counting ways of change from a list of coins and a given amount. I need to write a recursive generator code that presents the ways in every it…

Like button not recording the data [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Python, Pygame, Image manipulation: Restretch a loaded png, to be the texture for an isometric Tile

Im a 17 year old programmer, trying to program an isometric game in python, with pygame. After finishing a tile engine, working with not good looking, gimp-drawn PNGs, I wondered, if it would be possib…

TypeError: list object is not callable [duplicate]

This question already has answers here:TypeError: list object is not callable while trying to access a list(9 answers)Closed 10 years ago.I cant find the problem im facing... this is exactly what the …

Tokenise text and create more rows for each row in dataframe

I want to do this with python and pandas.Lets suppose that I have the following:file_id text 1 I am the first document. I am a nice document. 2 I am the second document. I am an even …

Is the example of the descriptor protocol in the Python 3.6 documentation incorrect?

I am new to Python and looking through its documentation I encountered the following example of the descriptor protocol that in my opinion is incorrect. .It looks like class IntField:def __get__(self, …

How to clean a string to get value_counts for words of interest by date?

I have the following data generated from a groupby(Datetime) and value_counts()Datetime 0 01/01/2020 Paul 803 2 01/02/2020 Paul 210982360967 1 …

Folium - Map doesnt appear

I try to get map through Folium but only thing I can see is marker on blank page. Id like to know where is problem lies, in explorer or coding. map.py import foliummap = folium.Map(location = [46.20, 6…

python tkinter exe built with cx_Freeze for windows wont show GUI

PROBLEM SOLVED. the issue was with jaraco module, that i used for clipboard manipulation, i used pyperclip instead.I made a python app with tkinter that works fine, but I wanted to make an exe from it …

lxml tree connection and properties

I have a .dtsx file so, I have multiple components with connections, so I need to extract component that have especific connection, but I can not handle that, example: <components><component r…