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

Travis CI运行Python pytest构建时提示Module not found报错求助

报错原因

核心原因是项目的依赖声明不完整:

  • 测试代码中导入了第三方库requests,但你的requirements.txt文件仅声明了pytest依赖,未添加requests的依赖声明
  • Travis CI的构建环境是全新的干净环境,不会默认预装requests这类非标准库的第三方包,因此执行测试导入requests时就会触发ModuleNotFoundError

额外的冗余问题:你的travis.yml中install段单独执行了pip install pytest,但requirements.txt已经包含pytest依赖,该语句属于冗余配置,不会触发报错但可以优化。

解决方法
  • 修改requirements.txt文件,添加requests依赖声明,修改后内容示例如下:
pytest==4.6
requests>=2.25.1

你可以根据自己的实际需求调整requests的版本号。

  • (可选优化)删除travis.yml中install段冗余的pip install pytest语句,修改后的install配置如下:
install:
 - "pip install -r requirements.txt"
  • 提交修改后的文件重新触发Travis CI构建即可正常运行测试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 12:24:04