1
votes

--- 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.

2

2 Answers

1
votes

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!

0
votes

Run this command pip install firebase-admin flask