0

Im trying to install the gym atari package on version 0.9.5 (I specifically need this version), but when I run the code (which is supposed to be running smoothly if gym is properly downloaded), I get the following error:

AttributeError: 'AtariEnv' object has no attribute 'viewer'

The problem occurred when I tried to run gym.make().

Does anyone know how to fix this?


The same behavior happened to me with python 3.9, but for some reason not on python 3.8 (there was a different error there). Maybe Im missing some rendering library?


The full error message is:

[2021-05-22 02:17:05,405] Making new env: PongNoFrameskip-v4
C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\envs\registration.py:17: PkgResourcesDeprecationWarning: Parameters to load are deprecated.  Call .resolve and .require separately.
  result = entry_point.load(False)
Traceback (most recent call last):
  File "C:/Users/1/PycharmProjects/University Homework/Reinforcement Learning/dqn/main.py", line 61, in <module>
    env = get_env(task, seed)
  File "C:\Users\1\PycharmProjects\University Homework\Reinforcement Learning\dqn\utils\gym.py", line 13, in get_env
    env = gym.make(env_id)
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\envs\registration.py", line 164, in make
    return registry.make(id)
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\envs\registration.py", line 122, in make
    env = spec.make()
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\envs\registration.py", line 89, in make
    env = cls(**self._kwargs)
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\envs\atari\atari_env.py", line 32, in __init__
    self.game_path = atari_py.get_game_path(game)
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\atari_py\games.py", line 20, in get_game_path
    raise Exception('ROM is missing for %s, see https://github.com/openai/atari-py#roms for instructions' % (game_name,))
Exception: ROM is missing for pong, see https://github.com/openai/atari-py#roms for instructions
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\utils\closer.py", line 67, in close
    closeable.close()
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\core.py", line 164, in close
    self.render(close=True)
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\core.py", line 150, in render
    return self._render(mode=mode, close=close)
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\envs\atari\atari_env.py", line 109, in _render
    if self.viewer is not None:
AttributeError: 'AtariEnv' object has no attribute 'viewer'
Exception ignored in: <function Env.__del__ at 0x00000203EE2174C8>
Traceback (most recent call last):
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\core.py", line 203, in __del__
    self.close()
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\core.py", line 164, in close
    self.render(close=True)
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\core.py", line 150, in render
    return self._render(mode=mode, close=close)
  File "C:\Users\1\PycharmProjects\University Homework\venv37\lib\site-packages\gym\envs\atari\atari_env.py", line 109, in _render
    if self.viewer is not None:
AttributeError: 'AtariEnv' object has no attribute 'viewer'

Also, the relevant code:

if __name__ == '__main__':
    # Get Atari games.
    benchmark = gym.benchmark_spec('Atari40M')
    
    # Change the index to select a different game.
    task = benchmark.tasks[3]
    
    # Run training
    seed = 0 # Use a seed of zero (you may want to randomize the seed!)
    env = get_env(task, seed)

And get_env is:

def get_env(task, seed):
    env_id = task.env_id

    env = gym.make(env_id)

    set_global_seeds(seed)
    env.seed(seed)

    expt_dir = 'tmp/gym-results'
    env = wrappers.Monitor(env, expt_dir, force=True)
    env = wrap_deepmind(env)

    return env
nir shahar
  • 328
  • 3
  • 13
  • maybe use `3.8` if it works. Different version has different functions and sometimes they need own version of modules. – furas May 21 '21 at 23:13
  • @furas it doesn't. When I try `3.8` I have a missing `ale_c.dll` problem, and couldn't find a formal source for the dll file, so I moved to try `3.7` and other versions – nir shahar May 21 '21 at 23:14
  • we can't see your code, we can't run it, we can't read in your mind - you should add all details in question. Without all details we don't know what could be the problem and how to help. – furas May 21 '21 at 23:14
  • The code is very long (its a skeleton my teacher created), I will try to add here the relevant bits – nir shahar May 21 '21 at 23:15
  • always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot, not link to external portal). There are other useful information. – furas May 21 '21 at 23:16
  • if code is long then show part which gives error and full code put on GitHub and add link in question - not in comment. It will be more readable in question and more people may see it. – furas May 21 '21 at 23:17

1 Answers1

1

The error looks like the Atari ROM for pong is not found. This is probably due to the fact that gym no longer installs ROMs automatically, due to licensing issues.

But there's an easy workaround now:

pip install -U gym
pip install -U gym[atari,accept-rom-license]

The accept-rom-license option installs a package called autorom which provides the AutoROM command, and runs it automatically with the --accept-rom-license option.

Then everything just works normally.

Details:

If you run AutoROM without the --accept-license option, this is what you get, so be warned:

AutoROM will download the Atari 2600 ROMs.
They will be installed to:
    [...]/site-packages/AutoROM/roms

Existing ROMs will be overwritten.

I own a license to these Atari 2600 ROMs.
I agree to not distribute these ROMs and wish to proceed: [Y/n]:

Run AutoROM --help for more options.

MiniQuark
  • 46,633
  • 36
  • 147
  • 183