Firebase Functions中更换Python运行时及配置ffmpeg的问题求助
Firebase Functions 中解决 FFmpeg 缺失问题的两种方案
方案一:切换到 Python 3.9 运行时
- 修正配置文件:打开项目根目录的
firebase.json,将对应函数的runtime字段设置为python39,示例配置:{ "functions": { "source": "functions", "runtime": "python39" } } - 检查依赖兼容性:确认
requirements.txt中的第三方包均支持Python 3.9,避免版本冲突。 - 完整部署命令:执行部署时带上必要参数(如触发器类型、地区),若有缓存问题可加
--no-cache强制重建:gcloud functions deploy <你的函数名> --runtime python39 --trigger-http --region <你的地区> --no-cache
方案二:在 Python 3.11 运行时中安装 FFmpeg
Python 3.11 环境未预装 FFmpeg,可通过部署阶段自动安装:
- 在
functions目录下创建apt.txt文件,写入一行内容:ffmpeg - 代码中直接调用
ffmpeg即可,无需自定义路径(apt安装后会加入系统可执行路径),示例代码:import subprocess import shlex result = subprocess.run(shlex.split("ffmpeg -version"), capture_output=True, text=True) print(result.stdout) - 重新部署函数,平台会自动读取
apt.txt并安装FFmpeg。
内容的提问来源于stack exchange,提问作者MrBom
相关产品推荐
相关产品推荐

