简体   繁体   English

Python 和 Firebase Firestore 错误 无法导入 Cloud Firestore 库

[英]Python and Firebase Firestore error Failed to import the Cloud Firestore library

I want to connect my Raspberry Pi 4B to Firebase Firestore.我想将我的 Raspberry Pi 4B 连接到 Firebase Firestore。 I'm using VS Code and SSH to write code on the RPi.我正在使用 VS Code 和 SSH 在 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.当我在本地计算机上使用 PyCharm 并执行相同的导入时,一切顺利。

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)

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.您可以通过在两者上运行python3 -m pip freeze检查包,看看它们是否不同。

If that doesn't help to identify any missing dependency, you can try to install the packages required like grcp如果这无助于识别任何缺失的依赖项,您可以尝试安装所需的软件包,例如grcp

pip install grpcio

Reinstalling “google-cloud-firestore”重新安装“google-cloud-firestore”

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

Or uninstalling and reinstalling “google-cloud-firestore”或卸载并重新安装“google-cloud-firestore”

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

As suggested in this question .正如这个问题所建议的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM