You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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,可通过部署阶段自动安装:

  1. 在functions目录下创建apt.txt文件,写入一行内容:
    ffmpeg
    
  2. 代码中直接调用ffmpeg即可,无需自定义路径(apt安装后会加入系统可执行路径),示例代码:
    import subprocess
    import shlex
    
    result = subprocess.run(shlex.split("ffmpeg -version"), capture_output=True, text=True)
    print(result.stdout)
    
  3. 重新部署函数,平台会自动读取apt.txt并安装FFmpeg。

内容的提问来源于stack exchange,提问作者MrBom

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 17:55:00