我在我的 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:start
或 firebase 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/