Pip Install Gymnasium[box2d] 失败
今天遇到个诡异的问题,想试玩一下 gymnasium 的时候按照指示需要先后安装 swig 和 gymnasium[box2d]。我首先创建了一个 venv 虚拟环境,然后安装 swig 和 gymnasium[box2d]
pip install swig gymnasium
但是会报如下错误:
Requirement already satisfied: gymnasium[box2d] in d:\documents\learn\gymnasium\.venv\lib\site-packages (1.0.0)
Requirement already satisfied: numpy>=1.21.0 in d:\documents\learn\gymnasium\.venv\lib\site-packages (from gymnasium[box2d]) (2.1.2)
Requirement already satisfied: cloudpickle>=1.2.0 in d:\documents\learn\gymnasium\.venv\lib\site-packages (from gymnasium[box2d]) (3.1.0)
Requirement already satisfied: typing-extensions>=4.3.0 in d:\documents\learn\gymnasium\.venv\lib\site-packages (from gymnasium[box2d]) (4.12.2)
Requirement already satisfied: farama-notifications>=0.0.1 in d:\documents\learn\gymnasium\.venv\lib\site-packages (from gymnasium[box2d]) (0.0.4)
Collecting box2d-py==2.3.5 (from gymnasium[box2d])
Using cached box2d-py-2.3.5.tar.gz (374 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting pygame>=2.1.3 (from gymnasium[box2d])
Using cached pygame-2.6.1-cp312-cp312-win_amd64.whl.metadata (13 kB)
Requirement already satisfied: swig==4.* in d:\documents\learn\gymnasium\.venv\lib\site-packages (from gymnasium[box2d]) (4.2.1)
Using cached pygame-2.6.1-cp312-cp312-win_amd64.whl (10.6 MB)
Building wheels for collected packages: box2d-py
Building wheel for box2d-py (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for box2d-py (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [21 lines of output]
Using setuptools (version 75.2.0).
C:\Users\Administrator\AppData\Local\Temp\pip-build-env-f86pf3pa\overlay\Lib\site-packages\setuptools\_distutils\dist.py:261: UserWarning: Unknown distribution option: 'test_suite'
warnings.warn(msg)
running bdist_wheel
running build
running build_py
creating build\lib.win-amd64-cpython-312\Box2D
copying library\Box2D\Box2D.py -> build\lib.win-amd64-cpython-312\Box2D
copying library\Box2D\__init__.py -> build\lib.win-amd64-cpython-312\Box2D
creating build\lib.win-amd64-cpython-312\Box2D\b2
copying library\Box2D\b2\__init__.py -> build\lib.win-amd64-cpython-312\Box2D\b2
running build_ext
building 'Box2D._Box2D' extension
swigging Box2D\Box2D.i to Box2D\Box2D_wrap.cpp
swig.exe -python -c++ -IBox2D -small -O -includeall -ignoremissing -w201 -globals b2Globals -outdir library\Box2D -keyword -w511 -D_SWIG_KWARGS -o Box2D\Box2D_wrap.cpp Box2D\Box2D.i
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "D:\Documents\learn\Gymnasium\.venv\Scripts\swig.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'swig'
error: command 'D:\\Documents\\learn\\Gymnasium\\.venv\\Scripts\\swig.exe' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for box2d-py
Failed to build box2d-py
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (box2d-py)
看错误信息应该是找不到 swig 这个包,但确实安装了的。重启终端,再试试,还是不行。于是上网找了好几个方法,都不大行。然后想手动安装 swig 试试,但是下载下来的压缩包也没有 swig.exe 这个文件,明明文档里说会附带的。接着就尝试按指引把程序 build 出来吧,但是也是有问题。着实是有点崩溃。
最后突然想到用 conda 试试吧, 创了个 python3.11 的 conda 环境,用 conda 进行安装:
conda install swig
conda install gymnasium[box2d]
结果还真行了。真是奇怪呢。
Banner Photo by tsuyoshi kozu on Unsplash
Pip Install Gymnasium[box2d] 失败
https://worranhin.github.io/2024/10/17/pip-conda/