简体   繁体   English

Firestore AttributeError:模块“firebase_admin”没有属性“firestore”

[英]Firestore AttributeError: module 'firebase_admin' has no attribute 'firestore'

I encountered a problem when importing the Firestore module from package firebase_admin.从包 firebase_admin 导入 Firestore 模块时遇到问题。

import firebase_admin
from firebase_admin import credentials

cred = credentials.ApplicationDefault()  

firebase_admin.initialize_app(cred, {
  'projectId': "...",
})

db = firebase_admin.firestore.client()

i installed the firebase_admin package using:我使用以下方法安装了 firebase_admin 包:

pip install --upgrade firebase-admin

But it returned:但它返回:

AttributeError: module 'firebase_admin' has no attribute 'firestore'

I wonder if i missed something.我想知道我是否错过了什么。

面临同样的问题,添加以下导入对我有用

from firebase_admin import firestore 

The import part is correct.导入部分是正确的。 You did the import of the library and resources correctly.您正确导入了图书馆和资源。

However, the part of the db = firebase_admin.firestore.client() it's not completely well set.但是, db = firebase_admin.firestore.client()的部分没有完全设置好。 This method needs a parameter for it to be called correctly.此方法需要一个参数才能正确调用。 As it's explained in the official documentation here :由于它的官方文档中解释真实这里

Parameters: app – An App instance (optional)参数: app – 一个 App 实例(可选)

So, even if you don't to send a specific app, you need to set it as none , for the method to be called correctly.因此,即使您不发送特定应用程序,也需要将其设置为none ,以便正确调用该方法。 Another example of how to call the method can be found in the official repository from Firebase, accessible via this link .如何调用该方法的另一个示例可以在 Firebase 的官方存储库中找到,可通过此链接访问。

Let me know if the information helped you!如果这些信息对您有帮助,请告诉我!

You can't use你不能使用

firebase_admin.firestore

but you can use但你可以使用

from firebase_admin import firestore

Hope this helps !希望这可以帮助 !

Solutions -解决方案 -

  1. I had the same error when i was using python 3.8 and then I switched to python 3.7 and that's how I solved my issue.我在使用python 3.8时遇到了同样的错误,然后切换到python 3.7 ,这就是我解决问题的方法。
  2. Rather using firebase_admin.firestore import the module from firebase_admin import firestore .而是使用firebase_admin.firestore导入模块from firebase_admin import firestore

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

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