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

Cloud Build执行pytest报错:无法找到Ghostscript库(libgs)

解决Cloud Build中Ghostscript依赖缺失的问题

你遇到的问题确实是因为Cloud Build使用的python:3.7镜像默认没有安装系统级的Ghostscript库(libgs),而Python的ghostscript包依赖这个系统库才能正常工作。你之前尝试的apt-get命令失败,大概率是因为没有先更新APT源,或者命令格式不对。

修改你的deploy.yaml测试步骤

只需要在安装Python依赖前,先通过APT安装系统级的Ghostscript即可,具体修改如下:

- name: 'docker.io/library/python:3.7'
  id: Test
  entrypoint: /bin/sh
  dir: 'My_Project/'
  args:
    - -c
    - 'apt-get update && apt-get install -y ghostscript && pip install -r requirements.txt && pytest pytest/test_mainpytest.py -v'

关键说明:

  • apt-get update:必须先执行这个命令,更新APT的软件源列表,否则可能找不到ghostscript包
  • apt-get install -y ghostscript:安装系统级的Ghostscript库,-y参数会自动确认安装,避免交互等待
  • 顺序很重要:一定要先安装系统依赖,再安装Python的ghostscript包,否则pip安装后依然找不到系统库

这样修改后,Cloud Build环境就会先安装好Ghostscript,再执行pip安装和pytest测试,应该就能解决你遇到的RuntimeError: Can not find Ghostscript library (libgs)错误了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 17:02:46