firebase / firebase-admin-python

Firebase Admin Python SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.03k stars 320 forks source link

how to install and use firebase-admin-python sdk on raspberry pi 4 model b armv7l #608

Closed hamad-9 closed 2 years ago

hamad-9 commented 2 years ago

I'm trying to connect the raspberry pi to the firestore I downloaded the package using the following command sudo pip install firebase-admin this is my code

import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
from google.cloud.firestore_v1 import Increment
#from lcd import LcdDisplay

class Database(object):
    __instance = None
    @staticmethod 
    def getInstance():
        if Database.__instance == None:
            Database()
        return Database.__instance

    def __init__(self):
        if Database.__instance != None:
            raise Exception("This class is a singleton!")
        else:
            Database.__instance = self
            # initializing firebase
            self.cred = credentials.Certificate('moneybank-firebase-adminsdk.json')
            self.firebase_admin = firebase_admin.initialize_app(self.cred)
            self.db = firestore.client()
            # initializing lcd
            #self.lcd = LcdDisplay.getInstance()

    def add_banknote(self, id):
            ref = self.db.collection(u'banknotes').document(f'{id}')
            ref.update({ 'amount' :  Increment(1)})
            ref = self.db.collection(u'total').document(f'{id[:3:]}')
            ref.update({ f'{id[:3:]}' :  Increment(int(id[4::])) })
            #self.lcd.setLine2(self.lcd.line2+"====")

    def get_total(self):
        return{
            "ils": self.db.collection("total").document("ils").get().to_dict()["ils"],
            "jod": self.db.collection("total").document("jod").get().to_dict()["jod"],
            "usd": self.db.collection("total").document("usd").get().to_dict()["usd"]
        }

db = Database.getInstance()
print(db.get_total())

and when I run the file the following error occurs

/usr/bin/python /home/pi/Desktop/moneybank/database.py Traceback (most recent call last): File "/usr/local/lib/python3.9/dist-packages/firebase_admin/firestore.py", line 22, in from google.cloud import firestore # pylint: disable=import-error,no-name-in-module File "/home/pi/.local/lib/python3.9/site-packages/google/cloud/firestore.py", line 18, in from google.cloud.firestore_v1 import version File "/home/pi/.local/lib/python3.9/site-packages/google/cloud/firestore_v1/init.py", line 30, in from google.cloud.firestore_v1._helpers import GeoPoint File "/home/pi/.local/lib/python3.9/site-packages/google/cloud/firestore_v1/_helpers.py", line 22, in from google.api_core import gapic_v1 # type: ignore File "/home/pi/.local/lib/python3.9/site-packages/google/api_core/gapic_v1/init.py", line 16, in from google.api_core.gapic_v1 import config File "/home/pi/.local/lib/python3.9/site-packages/google/api_core/gapic_v1/config.py", line 23, in import grpc File "/usr/local/lib/python3.9/dist-packages/grpc/init.py", line 22, in from grpc import _compression File "/usr/local/lib/python3.9/dist-packages/grpc/_compression.py", line 15, in from grpc._cython import cygrpc ImportError: /usr/local/lib/python3.9/dist-packages/grpc/_cython/cygrpc.cpython-39-arm-linux-gnueabihf.so: undefined symbol: __atomic_exchange_8

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/pi/Desktop/moneybank/database.py", line 5, in from firebase_admin import firestore File "/usr/local/lib/python3.9/dist-packages/firebase_admin/firestore.py", line 28, in raise ImportError('Failed to import the Cloud Firestore library for Python. Make sure ' ImportError: Failed to import the Cloud Firestore library for Python. Make sure to install the "google-cloud-firestore" module.

note that: the same file is working on my laptop and this is the expected output {'ils': 470, 'jod': 20, 'usd': 0}

google-oss-bot commented 2 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

lahirumaramba commented 2 years ago

Raspberry Pi is not an official platform we support. However, I came across this doing a quick search on your error. There are a couple fixes mentioned in that thread.

In the future, please use Stack Overflow to ask usage questions. Thanks!