【问题标题】:Python and Firebase Firestore error Failed to import the Cloud Firestore libraryPython 和 Firebase Firestore 错误无法导入 Cloud Firestore 库
【发布时间】:2022-01-23 02:01:02
【问题描述】:

我想将我的 Raspberry Pi 4B 连接到 Firebase Firestore。我正在使用 VS Code 和 SSH 在 RPi 上编写代码。我做了所有必要的导入,但出现了这个错误:

Failed to import the Cloud Firestore library for Python. Make sure to install the "google-cloud-firestore" module.

错误与这行代码有关:

from firebase_admin import firestore

当我在本地计算机上使用 PyCharm 并执行相同的导入时,一切顺利。

这是我的代码:

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)

【问题讨论】:

    标签: python firebase google-cloud-firestore


    【解决方案1】:

    您发布的代码完全没问题。其实和文档是一样的,可能是和树莓派有关的东西,并不是说它有问题,而是环境和依赖可能和你本地的不一样,导致它在树莓派中无法运行,但是在您的计算机上工作。您可以通过在两者上运行python3 -m pip freezecheck the packages 以查看它们是否不同。

    如果这无助于识别任何缺失的依赖项,您可以尝试安装所需的包,例如 grcp

    pip install grpcio
    

    重新安装“google-cloud-firestore”

    pip install google-cloud-core
    pip install google-cloud-firestore
    

    或者卸载并重新安装“google-cloud-firestore”

    pip uninstall google-cloud-firestore
    pip install google-cloud-firestore
    

    正如question 中所建议的那样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-24
      • 2021-11-05
      • 2021-12-06
      • 2021-01-01
      • 1970-01-01
      • 2018-12-30
      • 2021-11-05
      • 2020-05-22
      相关资源
      最近更新 更多