gpt4 book ai didi

python - firebase admin pip install 出现错误后

转载 作者:太空宇宙 更新时间:2023-11-03 21:32:41 24 4
gpt4 key购买 nike

我已经为 python2 安装了 firebase-admin pip

sudo pip install firebase-admin

创建一个文件并导入它,它在 python2 中工作正常

import firebase_admin

但是当我使用“凭据”时,它会生成错误

import firebase_admin
from firebase_admin import credentials

Traceback (most recent call last):
File "/var/www/html/google.py", line 24, in <module>
from firebase_admin import credentials
File "/usr/local/lib/python2.7/dist-packages/firebase_admin/__init__.py", line 23, in <module>
from firebase_admin import credentials
File "/usr/local/lib/python2.7/dist-packages/firebase_admin/credentials.py", line 21, in <module>
from google.auth.transport import requests
File "/usr/local/lib/python2.7/dist-packages/google/auth/transport/requests.py", line 37, in <module>
from google.auth import exceptions
File "/var/www/html/google.py", line 24, in <module>
from firebase_admin import credentials
ImportError: cannot import name credentials

最佳答案

我建议你使用python 3。

Few libraries are not supported on the App Engine standard python 2.7 runtime. They are supported on the Python 3 runtime for standard. (Reference)

下面的代码将修复您的凭据导入错误。

import firebase_admin
from firebase_admin import auth
from firebase_admin import credentials

# Initialize the default app
cred = credentials.Certificate('path/to/serviceAccountKey.json')
default_app = firebase_admin.initialize_app(cred)

有用链接:https://firebase.google.com/docs/admin/setup

关于python - firebase admin pip install 出现错误后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53441090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com