You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pyrebase安装与初始化报错求助:MutableMapping及initialize_app属性缺失

Pyrebase 安装与初始化问题解决

问题根源

  1. 旧版pyrebase未适配Python 3.10+版本,该版本中collections.MutableMapping已迁移至collections.abc.MutableMapping,因此触发AttributeError: module 'collections' has no attribute 'MutableMapping'错误。
  2. 切换至pyrebase4后,因包名实际为pyrebase4,直接import pyrebase无法定位到正确模块,导致AttributeError: module 'pyrebase' has no attribute 'initialize_app'。

解决步骤

  1. 彻底卸载旧版pyrebase并安装最新版pyrebase4:
    pip uninstall pyrebase -y
    pip install pyrebase4 --upgrade
    
  2. 修改代码导入逻辑,两种方式可选:
    • 用别名兼容原有代码:将import pyrebase替换为import pyrebase4 as pyrebase
    • 直接使用pyrebase4作为模块名:代码中调用pyrebase4.initialize_app(...)

修改后的完整代码

import pyrebase4 as pyrebase

firebaseConfig = {
        'apiKey': "AIzaSyCdjchW9VDCwJa38sSmM5GqNu8GuLMmhNE",
        'authDomain': "fir-login-78707.firebaseapp.com",
        'databaseURL': "https://fir-login-78707-default-rtdb.firebaseio.com",
        'projectId': "fir-login-78707",
        'storageBucket': "fir-login-78707.appspot.com",
        'messagingSenderId': "589888925876",
        'appId': "1:589888925876:web:24d05ad6224c5934d567e1"
}

firebase = pyrebase.initialize_app(firebaseConfig)
auth = firebase.auth()

内容的提问来源于stack exchange,提问作者YuuNagi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 11:47:35