python - Firebase Cloud Functions Python - 无法添加依赖项

标签 python firebase google-cloud-functions

我在我的 firebase 项目中使用 python 云函数。初始化云功能后,将 firebase-admin 添加到 requirements.txt 文件中,我可以使用 firebase emulators:start 进行测试,并且也成功使用 firebase deploy --only 函数 进行部署。

问题是当我尝试添加其他包时。我将 tldextract 添加到 requirements.txt 中,并将 import tldextract 放入 main.py 中,这会导致

ModuleNotFoundError: No module named 'tldextract'

127.0.0.1 - - [14/Jun/2023 00:24:10] "GET /__/functions.yaml HTTP/1.1" 500 -

⬢  functions: Failed to load function definition from source: FirebaseError: Failed to parse build specification

当我运行 firebase emulators:startfirebase deploy --only 函数 时。 venv 文件夹似乎也没有更新。

我尝试激活 venv 和 pip install -rrequirements.txt ,这使得本地执行可以与 firebase emulators:start 一起使用,但是在重新部署功能后,它们'在云中仍然失败。

我用不同的包尝试了这一点,以确保它不仅仅是这个特定的包。但是,对于我测试的所有包,将其他 pip 包添加到 requirements.txt 并将其导入到 main.py 中都失败了。

我做错了什么?

最佳答案

以下内容为我解决了这个问题:

删除由 firebase init 函数 创建的 venv 文件夹。

按如下方式创建一个新的:

python3.11 -m venv venv
source venv/bin/activate
pip3 install --upgrade pip
python3.11 -m pip install -r requirements.txt

现在使用 firebase deploy --only 函数进行部署

关于python - Firebase Cloud Functions Python - 无法添加依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76469459/

相关文章:

python - 在 pandas 中,如何在数据框中显示最常见的诊断,但只计算每个患者出现 1 次相同的诊断

python - 如何从具有透明背景的 matplotlib 导出绘图?

firebase - 从Firestore获取数据

swift - 检查用户是否已经存在 Firebase swift 3.0

javascript - 尝试在异步云函数( Node v8)中执行 fs.writefile()

google-cloud-firestore - 当函数目录位于不同的项目/位置时运行 firebase 模拟器

python - 如何使用 Python 2 和 Python 3 中的内置库 ElementTree 等实体解析 HTML?

firebase - 在我的 Flutter Web 应用程序中按 Altright 时出错

google-chrome - 可以在 Google Cloud Function 中运行 Headless Chrome/Chromium 吗?

python - 从 Paraview 4.2 中提取 Python 脚本中的数据