cannot import name 'BinarySpaceToDiscreteSpaceEnv' Solve

 


Problem

When you program using gym-super-mario-bros, you can see this error.

Traceback (most recent call last):
  File "1_sb_ppo_agent.py", line 10, in <module>
    from nes_py.wrappers import BinarySpaceToDiscreteSpaceEnv
ImportError: cannot import name 'BinarySpaceToDiscreteSpaceEnv' from 'nes_py.wrappers' (C:\Users\Anaconda3\lib\site-packages\nes_py\wrappers\__init__.py)

Solve

Maybe, because of version changed, You have to use JoypadSpace, not BinarySpaceToDiscreteSpaceEnv. https://github.com/Kautenja/nes-py/wiki/Wrappers. There is a solution. You have to change from BinarySpaceToDiscreteSpaceEnv to JoypadSpace. Like below example.

from nes_py.wrappers import JoypadSpace
env = JoypadSpace(env, [
    ['NOP'],
    ['right', 'A'],
    ['left', 'A'],
    ['A'],
])