I want to connect my Raspberry Pi 4B to Firebase Firestore. I'm using VS Code and SSH to write code on the RPi. I did all the necessary imports but I got this error:
Failed to import the Cloud Firestore library for Python. Make sure to install the "google-cloud-firestore" module.
The error realtes to this line of code:
from firebase_admin import firestore
When I use PyCharm on my local computer and I do the same imports, everything goes well.
This is my code:
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
# Use a service account
cred = credentials.Certificate('***.json')
firebase_admin.initialize_app(cred)
CodePudding user response:
The code you posted is completely fine. Actually, it is the same as the documentation, which may suggest it is something related to the Raspberry Pi, not meaning it is faulty, but the environment and dependencies might be different from your local one, causing it to not run in the Raspberry but work on your computer. You can check the packages by running python3 -m pip freeze
on both to see if they are different.
If that doesn’t help to identify any missing dependency, you can try to install the packages required like grcp
pip install grpcio
Reinstalling “google-cloud-firestore”
pip install google-cloud-core
pip install google-cloud-firestore
Or uninstalling and reinstalling “google-cloud-firestore”
pip uninstall google-cloud-firestore
pip install google-cloud-firestore
As suggested in this question.