Data Science/Trouble Shooting

[강화학습] gymnasium - box2d install 오류 해결

dev-js 2024. 9. 24. 22:46

 

728x90

 

[강화학습] gymnasium - box2d install 오류 해결

 

* 필자는 Window10 환경에서 gymnasium 라이브러리를 설치했습니다.

 

강화학습을 위해 gymnasium 라이브러리를 다운로드 중

pip install gymnasium
pip install gymnasium[classic-control]
pip install gymnasium[box2d]

 

pip install gymnasium[box2d] 에서 오류가 뜰 수 있다.

크게 swig 에러, C++ build tool 에러 두 개가 있다.

두 오류가 모두 떠본 사람으로서 해당 오류를 트러블슈팅 하고자 한다.

 

 

 

SWIG err

  Building wheel for box2d-py (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      Using setuptools (version 68.2.2).
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-311
      creating build\lib.win-amd64-cpython-311\Box2D
      copying library\Box2D\Box2D.py -> build\lib.win-amd64-cpython-311\Box2D
      copying library\Box2D\__init__.py -> build\lib.win-amd64-cpython-311\Box2D
      creating build\lib.win-amd64-cpython-311\Box2D\b2
      copying library\Box2D\b2\__init__.py -> build\lib.win-amd64-cpython-311\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
      error: command 'swig.exe' failed: None
      [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
  Running setup.py clean for box2d-py
Failed to build box2d-py
ERROR: Could not build wheels for box2d-py, which is required to install pyproject.toml-based projects

 

아래와 같이 오류가 뜬다면 swig 에러가 뜬 것이다.

나는 'swig.exe' 파일이 존재하지 않아 에러가 떴었다.

 

해결방법

  1. swig 다운로드 링크에 들어가서 swig 최신버전 다운로드
  2. 다운로드된 swig 압축 파일을 C 드라이브로 압축 풀고 폴더 이름 'swig' 으로 변경
  3. C 드라이브에 있는 swig 파일의 파일 경로를 복사 ( ex. "C:\swig" )
  4. 윈도우 검색 > 환경 변수 검색 > [시스템 속성] 창에서 환경변수 클릭 > 시스템 변수 Path 선택 후 편집
  5. 편집을 클릭 후 C:\swig 를 추가
  6. 프롬프트 창을 껐다 킨 후 다시 install
반응형

 

 

C++ build tool err

  Building wheel for box2d-py (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [28 lines of output]
      Using setuptools (version 68.2.2).
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-311
      creating build\lib.win-amd64-cpython-311\Box2D
      copying library\Box2D\Box2D.py -> build\lib.win-amd64-cpython-311\Box2D
      copying library\Box2D\__init__.py -> build\lib.win-amd64-cpython-311\Box2D
      creating build\lib.win-amd64-cpython-311\Box2D\b2
      copying library\Box2D\b2\__init__.py -> build\lib.win-amd64-cpython-311\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
      Box2D\Common\b2Math.h(67) : Warning 302: Redefinition of identifier 'b2Vec2' by %extend ignored,
      Box2D\Box2D_math.i(47) : Warning 302: %extend definition of 'b2Vec2'.
      Box2D\Common\b2Math.h(158) : Warning 302: Redefinition of identifier 'b2Vec3' by %extend ignored,
      Box2D\Box2D_math.i(168) : Warning 302: %extend definition of 'b2Vec3'.
      Box2D\Common\b2Math.h(197) : Warning 302: Redefinition of identifier 'b2Mat22' by %extend ignored,
      Box2D\Box2D_math.i(301) : Warning 302: %extend definition of 'b2Mat22'.
      Box2D\Common\b2Math.h(271) : Warning 302: Redefinition of identifier 'b2Mat33' by %extend ignored,
      Box2D\Box2D_math.i(372) : Warning 302: %extend definition of 'b2Mat33'.
      Box2D\Collision\b2DynamicTree.h(44) : Warning 312: Nested union not currently supported (ignored).
      Box2D\Common\b2Settings.h(144) : Warning 506: Can't wrap varargs with keyword arguments enabled
      Box2D\Common\b2Math.h(91) : Warning 509: Overloaded method b2Vec2::operator ()(int32) effectively ignored,
      Box2D\Common\b2Math.h(85) : Warning 509: as it is shadowed by b2Vec2::operator ()(int32) const.
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [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
  Running setup.py clean for box2d-py
Failed to build box2d-py
ERROR: Could not build wheels for box2d-py, which is required to install pyproject.toml-based projects

 

아래와 같은 오류가 뜬다면 c++ 빌드 오류가 뜬 것이다.

 

해결방법

  1. Microsoft Visual C++ 빌드 도구 설치
  2. 다운로드 후 실행
  3. 설치 시, "C++ Build Tools" 옵션을 선택하고, 필요한 C++ 컴파일러와 라이브러리 패키지를 포함해야 한다.
  4. 설치 후 프롬프트 창을 껐다 킨 후 다시 install
 

Microsoft C++ Build Tools - Visual Studio

 

visualstudio.microsoft.com

728x90