在尝试设置 Firebase 云功能和实时数据库后,我有了这个标准样板:
# Welcome to Cloud Functions for Firebase for Python!
# To get started, simply uncomment the below code or create your own.
# Deploy with `firebase deploy`
from firebase_functions import https_fn
from firebase_admin import initialize_app
# initialize_app()
#
#
@https_fn.on_request()
def on_request_example(req: https_fn.Request) -> https_fn.Response:
return https_fn.Response("Hello world!")
即使我做了 pip install
pip install firebase_functions
,我仍然从 PyCharm 获得 Unresolved reference 'firebase_functions'
。我该如何解决这个问题?
我遇到了同样的错误并尝试了这种方法来解决它:
配置你的Python解释器:
从“工具”菜单中,选择“同步 Python 要求...”,然后选择“配置”。在打开的对话框中,添加 Python 路径。或者,您可以通过转到文件 -> 项目结构 -> 平台设置 -> SDK 将 Python SDK 添加到项目设置中。
将上一步中的 Python SDK 主路径设置为位于项目函数文件夹内的 venv 文件夹。例如:
"my_project_path/functions/venv/bin/python3.12"
。
导航到functions/venv文件夹并运行以下命令:
python3.12 -m venv venv
source bin/activate
pip3 install -r requirements.txt