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

在Google Colab中pip install gym报错python setup.py egg_info失败的原因?

解决Google Colab安装gym==0.21.0[atari,accept-rom-license]的metadata生成失败问题

问题重现

安装指定版本gym时触发以下报错:

Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting gym[accept-rom-license,atari]==0.21.0
  Using cached gym-0.21.0.tar.gz (1.5 MB)
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Preparing metadata (setup.py) ... error
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details. 

已尝试升级pip、setuptools并安装ez_setup,问题未解决。

解决方案

方法1:回退到兼容版本的setuptools并补全依赖

gym 0.21.0与高版本setuptools存在兼容性冲突,需调整环境依赖:

  1. 安装适配的setuptools版本
pip install setuptools==58.0.4
  1. 安装编译所需的基础依赖
pip install numpy==1.21.6 swig
  1. 重新执行gym安装命令
pip install gym[accept-rom-license,atari]==0.21.0

方法2:禁用构建隔离(快速修复)

跳过安装过程中的环境隔离机制,强制使用当前环境依赖完成安装:

pip install gym[accept-rom-license,atari]==0.21.0 --no-build-isolation

方法3:更换为高版本gym(可选)

若无需严格使用0.21.0版本,可安装修复了metadata生成问题的稳定版本:

pip install gym[accept-rom-license,atari]==0.26.2

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 17:42:08