Yesterday I wanted to play with firebase messaging and python, but I encountered the following issue when trying to install the package: if I install the package (firebase-admin) through pip, the importation doesn't work in my project. I tried installing it through PyCharm (so in the virtual environment of my project) and it works perfectly. Does anyone know what I'm missing here? I checked and the package is correctly installed (version 5.1.0).
Also does anyone know is there is a difference between firebase-admin and firebase_admin? (I tried installing both)
Thanks
pip install firebase-admin
But once the package is on your machine, you import the individual modules from firebase_admin
in your code as follows:
from firebase_admin import firestore, initialize_app, <otherModule etc...>
As far as I've seen, there is no firebase_admin
package on PyPi- There may however be an alias to firebase-admin that I am unaware of, but do not take my word on this.
One reason you may be encountering issues when using Pycharm is that Jetbrains /Pycharm may be creating a Virtual Environment for you without you knowing.
By running pip install firebase-admin
in newly opened terminal, you install the package in your global python package index. If Pycharm is starting the Virtual Environment they've set up when you open the IDE, it likely won't have any knowledge of your global packages.
A good practice is to create your own Virtual Environment and activating it when you start working on the project.
You can create the officially supported venv environment by running,
python3 -m venv ./path/to/your/project/venv
Alternatively you can navigate to the root of your project and run python3 -m venv venv/
.
Now you should be able to activate it by running,
source venv/bin/activate
If you created the venv in Mac/Linux environment or,
.\venv\Scripts\activate
In Windows.
See the official docs Here.
Lastly, if you are uploading this project to a VCS repository like GitHub, don't forget to add venv/
to your .gitignore
as the folder can be quite large.