为什么“pip install gym”失败,并出现“python setup.py egg_info did not run successfully”错误?

错误如下:

...>pip install stable-baselines3==1.8.0
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting stable-baselines3==1.8.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/76/07/fb80e30764c9caf1c66d20c58ed5dea8c72c07ff7e9957f2ca9b11b2cdc8/stable_baselines3-1.8.0-py3-none-any.whl (174 kB)
     ---------------------------------------- 174.5/174.5 kB 2.6 MB/s eta 0:00:00
Collecting pandas
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f0/95/361d9726b57b44c1d8dce070930c2322a70157f697ecdcca13f4388247ab/pandas-2.0.2-cp38-cp38-win_amd64.whl (10.8 MB)
     ---------------------------------------- 10.8/10.8 MB 12.6 MB/s eta 0:00:00
Collecting matplotlib
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/92/01/2c04d328db6955d77f8f60c17068dde8aa66f153b2c599ca03c2cb0d5567/matplotlib-3.7.1-cp38-cp38-win_amd64.whl (7.6 MB)
     ---------------------------------------- 7.6/7.6 MB 13.2 MB/s eta 0:00:00
Collecting gym==0.21
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/4b/48/920cea66177b865663fde5a9390a59de0ef3b642ad98106ac1d8717d7005/gym-0.21.0.tar.gz (1.5 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [1 lines of output]
      error in gym setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
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.

结论

TL;DR降级setuptools==65.5.0wheel<0.40.0

pip install setuptools==65.5.0 "wheel<0.40.0"

解释

这里的问题似乎与wheel(0. 40. 0+)setuptools(66. 0. 0+)有关,它们现在报告gym==0.21.0的安装文件中的版本字符串不再有效。以下追溯来自Github #3202 for gym中报告的Gym构建轮

...
wheel.vendored.packaging.requirements.InvalidRequirement: Expected end or semicolon (after version specifier)
opencv-python>=3.

它引用setup.py中的opencv-python>=3.字符串。看起来较新版本的wheel在这里引发了错误。
您可以在Github issue #3211中找到的一种解决方法是降级setuptools和wheel的版本,如下所示:

pip install setuptools==65.5.0 "wheel<0.40.0"

重启内核后,你应该可以运行:

pip install gym==0.21.0

参考

。。。

你可能感兴趣的:(python,pip,开发语言)