Pyrebase安装与初始化报错求助:MutableMapping及initialize_app属性缺失
Pyrebase 安装与初始化问题解决
问题根源
- 旧版
pyrebase未适配Python 3.10+版本,该版本中collections.MutableMapping已迁移至collections.abc.MutableMapping,因此触发AttributeError: module 'collections' has no attribute 'MutableMapping'错误。 - 切换至
pyrebase4后,因包名实际为pyrebase4,直接import pyrebase无法定位到正确模块,导致AttributeError: module 'pyrebase' has no attribute 'initialize_app'。
解决步骤
- 彻底卸载旧版
pyrebase并安装最新版pyrebase4:pip uninstall pyrebase -y pip install pyrebase4 --upgrade - 修改代码导入逻辑,两种方式可选:
- 用别名兼容原有代码:将
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
相关产品推荐
相关产品推荐

