firebase管理pip安装后得到错误

cwtwac6a  于 2022-11-17  发布在  其他
关注(0)|答案(2)|浏览(131)

我已经为python2安装了firebase管理管道

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
ix0qys7i

ix0qys7i1#

I suggest you to use 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)
Below code will fix your credentials 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)

Useful link: https://firebase.google.com/docs/admin/setup

58wvjzkj

58wvjzkj2#

我可以看到你正在使用python版本2.7,这是不兼容的firebase-admin包。
根据文档,您需要Python版本〉=3.5
您可以从以下网址下载最新版本的python:
Python Latest Version Download

相关问题