我已经为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
答案 0 :(得分:0)
我建议您使用python 3。
App Engine标准python 2.7不支持少数库 运行。标准的Python 3运行时支持它们。 (Reference)
下面的代码将修复您的凭据ImportError。
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)
答案 1 :(得分:0)
我可以看到您使用的是 python 2.7 版,它与 firebase-admin 包不兼容。
根据文档,您需要 Python 版本 >=3.5
您可以从这里下载最新版本的python:
Python Latest Version Download