firebase / firebase-admin-python

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

Import Error: Failed to import Cloud Firestore Library for Python #658

Closed enahsor closed 1 year ago

enahsor commented 1 year ago

Describe your environment

Hardware Macbook Pro (M1, 2020)

Pip List

CacheControl             0.12.11
cachetools               5.2.0
certifi                  2022.9.24
cffi                     1.15.1
charset-normalizer       2.1.1
cryptography             38.0.1
firebase-admin           6.0.1
google-api-core          2.10.2
google-api-python-client 2.65.0
google-auth              2.13.0
google-auth-httplib2     0.1.0
google-cloud-core        2.3.2
google-cloud-firestore   2.7.2
google-cloud-storage     2.5.0
google-crc32c            1.5.0
google-resumable-media   2.4.0
googleapis-common-protos 1.56.4
grpcio                   1.50.0
grpcio-status            1.50.0
httplib2                 0.20.4
idna                     3.4
mccabe                   0.7.0
msgpack                  1.0.4
pip                      22.3
proto-plus               1.22.1
protobuf                 4.21.8
pyasn1                   0.4.8
pyasn1-modules           0.2.8
pycodestyle              2.9.1
pycparser                2.21
pydocstyle               6.1.1
pyflakes                 2.5.0
PyJWT                    2.6.0
pylama                   8.4.1
pyparsing                3.0.9
requests                 2.28.1
rsa                      4.9
setuptools               62.3.2
six                      1.16.0
snowballstemmer          2.2.0
uritemplate              4.1.1
urllib3                  1.26.12
wheel                    0.37.1

Describe the problem

Importing firestore from firebase_admin causes an ImportError - it throws this exception:

Traceback (most recent call last):
  File "/Users/d/Desktop/testing/fb-test/venv/lib/python3.10/site-packages/firebase_admin/firestore_async.py", line 30, in <module>
    from google.cloud import firestore # type: ignore # pylint: disable=import-error,no-name-in-module
  File "/Users/d/Desktop/testing/fb-test/venv/lib/python3.10/site-packages/google/cloud/firestore/__init__.py", line 18, in <module>
    from google.cloud.firestore_v1 import __version__
  File "/Users/d/Desktop/testing/fb-test/venv/lib/python3.10/site-packages/google/cloud/firestore_v1/__init__.py", line 30, in <module>
    from google.cloud.firestore_v1._helpers import GeoPoint
  File "/Users/d/Desktop/testing/fb-test/venv/lib/python3.10/site-packages/google/cloud/firestore_v1/_helpers.py", line 22, in <module>
    from google.api_core import gapic_v1
  File "/Users/d/Desktop/testing/fb-test/venv/lib/python3.10/site-packages/google/api_core/gapic_v1/__init__.py", line 16, in <module>
    from google.api_core.gapic_v1 import config
  File "/Users/d/Desktop/testing/fb-testvenv/lib/python3.10/site-packages/google/api_core/gapic_v1/config.py", line 23, in <module>
    import grpc
  File "/Users/d/Desktop/testing/fb-test/venv/lib/python3.10/site-packages/grpc/__init__.py", line 22, in <module>
    from grpc import _compression
  File "/Users/d/Desktop/testing/fb-test/venv/lib/python3.10/site-packages/grpc/_compression.py", line 15, in <module>
    from grpc._cython import cygrpc
ImportError: dlopen(/Users/d/Desktop/testing/fb-test/venv/lib/python3.10/site-packages/grpc/_cython/cygrpc.cpython-310-darwin.so, 0x0002): tried: '/Users/d/Desktop/testing/fb-test/venv/lib/python3.10/site-packages/grpc/_cython/cygrpc.cpython-310-darwin.so'
 (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))

Steps to reproduce:

  1. Install firebase-admin using pip install --upgrade firebase-admin
  2. Add from firebase_admin import firestore to a script file
  3. Run script file
google-oss-bot commented 1 year ago

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

xellosiris commented 1 year ago

Ihave same issue here

enahsor commented 1 year ago

Ihave same issue here

Are you also using pyenv to manage your python environments @xellosiris?

lahirumaramba commented 1 year ago

I think this is an issue in the grpcio library on M1 machines. See https://stackoverflow.com/questions/69788752/on-apple-m1-grpc-google-api-import-error

According to the github issue it should be fixed in grpcio 1.47.0 and newer. Some developers have also used the following as a workaround... which is mentioned here.

pip install --no-binary :all: grpcio --ignore-installed