ageron / handson-ml

⛔️ DEPRECATED – See https://github.com/ageron/handson-ml3 instead.
Apache License 2.0
25.12k stars 12.91k forks source link

Chapter 16: Unable to find game "MsPacman" #639

Closed yuan-fei closed 2 years ago

yuan-fei commented 2 years ago

I have gym, gym[atari], atari-py installed already, but I'm still getting the error ' Unable to find game "MsPacman"' when running chapter 16 RL.

env = gym.make('MsPacman-v0')
/usr/local/lib/python3.9/site-packages/ale_py/gym/environment.py:11: DeprecationWarning: Importing atari-py roms won't be supported in future releases of ale-py.
  import ale_py.roms as roms
A.L.E: Arcade Learning Environment (version +a54a328)
[Powered by Stella]
---------------------------------------------------------------------------
Error                                     Traceback (most recent call last)
/var/folders/vl/sv441mg56qj4q9s6050r7_fw0000gn/T/ipykernel_1594/2701575929.py in <module>
----> 1 env = gym.make('MsPacman-v0')

/usr/local/lib/python3.9/site-packages/gym/envs/registration.py in make(id, **kwargs)
    198 
    199 def make(id, **kwargs):
--> 200     return registry.make(id, **kwargs)
    201 
    202 

/usr/local/lib/python3.9/site-packages/gym/envs/registration.py in make(self, path, **kwargs)
    103             logger.info("Making new env: %s", path)
    104         spec = self.spec(path)
--> 105         env = spec.make(**kwargs)
    106         if env.spec.max_episode_steps is not None:
    107             from gym.wrappers.time_limit import TimeLimit

/usr/local/lib/python3.9/site-packages/gym/envs/registration.py in make(self, **kwargs)
     73         else:
     74             cls = load(self.entry_point)
---> 75             env = cls(**_kwargs)
     76 
     77         # Make the environment aware of which spec it came from.

/usr/local/lib/python3.9/site-packages/ale_py/gym/environment.py in __init__(self, game, mode, difficulty, obs_type, frameskip, repeat_action_probability, full_action_space, render_mode)
    121 
    122         # Seed + Load
--> 123         self.seed()
    124 
    125         self._action_set = (

/usr/local/lib/python3.9/site-packages/ale_py/gym/environment.py in seed(self, seed)
    169 
    170         if not hasattr(roms, self._game):
--> 171             raise error.Error(
    172                 f'Unable to find game "{self._game}", did you import {self._game} with ale-import-roms?'
    173             )

Error: Unable to find game "MsPacman", did you import MsPacman with ale-import-roms?
ageron commented 2 years ago

Hi @yuan-fei , Thanks for your feedback. The atari_py package used to include Atari ROMs, but they're not included anymore since version 0.2.7. So you have two options:

A. You can revert back to an atari_py version before 0.2.7.

If you're using Anaconda:

conda activate tf2  # assuming your conda environment is named tf2
conda install -c conda-forge atari_py==0.2.6

I'll update the notebook to install this version.

B. You can manually download the ROMs and add them to Gym's registry. This is more cumbersome, but it's probably the right way to do things going forward.

In your Jupyter notebook, run the following code from this StackOverflow answer (just once):

import urllib.request
urllib.request.urlretrieve('http://www.atarimania.com/roms/Roms.rar','Roms.rar')
!pip install unrar
!unrar x Roms.rar
!mkdir rars
!mv HC\ ROMS.zip   rars
!mv ROMS.zip  rars
!python -m atari_py.import_roms rars

Thanks again for bringing this issue to my attention.

yuan-fei commented 2 years ago

I tried option B and it works, thanks @ageron for the quick response!