본문 바로가기

프로그래밍/Python

[pyglet, gym_super_mario_bros] NSEventTrackingRunLoopMode : symbol not found

최근 머신러닝 공부중 발생한 문제와 해결 방법에 대해 공유합니다.

 

문제가 된 라이브러리

gym_super_mario_bros(에 종속된 하위 라이브러리)

 

 

실행한 소스코드

from nes_py.wrappers import JoypadSpace
import gym_super_mario_bros
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT
env = gym_super_mario_bros.make('SuperMarioBros-v0')
env = JoypadSpace(env, SIMPLE_MOVEMENT)

done = True

for step in range(5000):
	if done:
		state = env.reset()
	state, reward, done, info = env.step(env.action_space.sample())
    env.render()
    
env.close()

 

 

발생한 에러 메세지

Traceback (most recent call last):
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/pyglet/__init__.py", line 329, in __getattr__
    return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'key'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/app.py", line 35, in <module>
    env.render()
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/gym/core.py", line 240, in render
    return self.env.render(mode, **kwargs)
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/gym/core.py", line 240, in render
    return self.env.render(mode, **kwargs)
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/nes_py/nes_env.py", line 373, in render
    self.viewer = ImageViewer(
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/nes_py/_image_viewer.py", line 35, in __init__
    self.pyglet.window.key.ENTER: ord('\r'),
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/pyglet/__init__.py", line 335, in __getattr__
    __import__(import_name)
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/pyglet/window/__init__.py", line 1865, in <module>
    from pyglet.window.cocoa import CocoaWindow as Window
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/pyglet/window/cocoa/__init__.py", line 44, in <module>
    from pyglet.canvas.cocoa import CocoaCanvas
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/pyglet/canvas/__init__.py", line 102, in <module>
    from pyglet.canvas.cocoa import CocoaDisplay as Display
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/pyglet/canvas/cocoa.py", line 41, in <module>
    from pyglet.libs.darwin.cocoapy import CGDirectDisplayID, quartz, cf
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/pyglet/libs/darwin/__init__.py", line 36, in <module>
    from .cocoapy import *
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/pyglet/libs/darwin/cocoapy/__init__.py", line 37, in <module>
    from .cocoalibs import *
  File "/Users/jonginkoo/projects/mario-machine-learning-practice/.venv/lib/python3.9/site-packages/pyglet/libs/darwin/cocoapy/cocoalibs.py", line 200, in <module>
    NSEventTrackingRunLoopMode = c_void_p.in_dll(appkit, 'NSEventTrackingRunLoopMode')
ValueError: dlsym(RTLD_DEFAULT, NSEventTrackingRunLoopMode): symbol not found

 

윈도우에서 실행할땐 전혀 문제가 없던것이 Mac os에서만 위와 같은 에러가 발생했습니다.

 

구글링해보니 macOS의 Big Sur 업데이트 이 후 gym_super_mario_bros>gym>pyglet에 문제가 발생한 것이 원인

https://github.com/openai/gym/issues/2101

 

Gym on Mac OS X Big Sur · Issue #2101 · openai/gym

After updating OS all my scripts stopped working, most of the errors related to pyglet, and paths to some libraries, some errors that I came across: Error occurred while running `from pyglet.gl imp...

github.com


gym_super_mario_bros설치시 하위에 종속된 모듈중 pyglet의 버전이 1.5.0이상 설치가 되지 않게 되어있는데,

위 문제는 pyglet 1.5.11버전에 픽스되었다.

 

gym_super_mario_bros 설치 후

pyglet만 1.5.11로 수동으로 설치함.

 

pip uninstall pyglet
pip install pyglet==1.5.11

위 명령어를 통해 버전을 강제로 수정하면 아래와 같은 메세지가 나오는데 무시하고 진행하면 된다. (설치 시도한 버전이 기존에 설정되어있는 버전범위에서 벗어난다는 메세지)

 

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
nes-py 8.1.6 requires pyglet<=1.5.0,>=1.4.0, but you have pyglet 1.5.11 which is incompatible.

 

수정작업후 해당 리포지토리에 PR요청 후 마무리
https://github.com/Kautenja/nes-py/pull/77

 

'프로그래밍 > Python' 카테고리의 다른 글

Python Code Formatter Black 적용기  (0) 2021.07.14