openai / retro

Retro Games in Gym
MIT License
3.39k stars 526 forks source link

Can't load roms in gym #268

Open Shivam310 opened 2 years ago

Shivam310 commented 2 years ago

Issue summary

[Hi, I was setting up my project on a new pc and when I run my code I get this error:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Input In [1], in <cell line: 2>()
      1 #Import Dependencies
----> 2 import gym
      3 from stable_baselines3 import A2C
      4 from stable_baselines3.common.vec_env import VecFrameStack

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\gym\__init__.py:15, in <module>
      7 from gym.core import (
      8     Env,
      9     Wrapper,
   (...)
     12     RewardWrapper,
     13 )
     14 from gym.spaces import Space
---> 15 from gym.envs import make, spec, register
     16 from gym import logger
     17 from gym import vector

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\gym\envs\__init__.py:5, in <module>
      2 from gym.envs.registration import make, register, registry, spec
      4 # Hook to load plugins from entry points
----> 5 _load_env_plugins()
      8 # Classic
      9 # ----------------------------------------
     11 register(
     12     id="CartPole-v0",
     13     entry_point="gym.envs.classic_control.cartpole:CartPoleEnv",
     14     max_episode_steps=200,
     15     reward_threshold=195.0,
     16 )

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\gym\envs\registration.py:321, in load_env_plugins(entry_point)
    314         logger.warn(
    315             f"The environment namespace magic key `{plugin.name}` is unsupported. "
    316             "To register an environment at the root namespace you should specify "
    317             "the `__root__` namespace."
    318         )
    320 with context:
--> 321     fn = plugin.load()
    322     try:
    323         fn()

File ~\AppData\Local\Programs\Python\Python310\lib\importlib\metadata\__init__.py:171, in EntryPoint.load(self)
    166 """Load the entry point from its definition. If only a module
    167 is indicated by the value, return that module. Otherwise,
    168 return the named object.
    169 """
    170 match = self.pattern.match(self.value)
--> 171 module = import_module(match.group('module'))
    172 attrs = filter(None, (match.group('attr') or '').split('.'))
    173 return functools.reduce(getattr, attrs, module)

File ~\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py:126, in import_module(name, package)
    124             break
    125         level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\ale_py\gym.py:5, in <module>
      1 from collections import defaultdict, namedtuple
      3 from gym.envs.registration import register
----> 5 from ale_py.roms.utils import rom_name_to_id, rom_id_to_name
      8 GymFlavour = namedtuple("GymFlavour", ["suffix", "env_kwargs", "kwargs"])
      9 GymConfig = namedtuple("GymConfig", ["version", "env_kwargs", "flavours"])

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\ale_py\roms\__init__.py:89, in <module>
     85     return roms
     88 # Resolve all ROMs
---> 89 ROMS = resolve_roms()
     90 __all__ = list(ROMS.keys())
     93 def __dir__() -> List[str]:

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\ale_py\roms\__init__.py:40, in resolve_roms()
     36 for package in ROM_PLUGINS:
     38     try:
     39         # Resolve supported / unsupported roms
---> 40         supported, unsupported = package.resolve()
     42         # We'll now get the update delta. The reason for this is two fold:
     43         #     1) We should only display atari-py deprecation when it would have
     44         #        imported ROMs.
     45         #     2) ROM priority holds. When you import ROMs they'll all come from
     46         #        a single source of truth.
     47         #
     48         roms_delta_keys = list(
     49             filter(lambda rom: rom not in roms, supported.keys())
     50         )

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\ale_py\roms\utils.py:60, in SupportedPackage.resolve(self)
     56 unsupported: List[pathlib.Path] = []
     58 # Iterate over all ROMs in the specified package
     59 for resource in filter(
---> 60     lambda file: file.suffix == ".bin", resources.files(self.package).iterdir()
     61 ):
     62     resolved = resource.resolve()
     63     rom = ALEInterface.isSupportedROM(resolved)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\importlib_resources\_common.py:22, in files(package)
     17 def files(package):
     18     # type: (Package) -> Traversable
     19     """
     20     Get a Traversable resource from a package
     21     """
---> 22     return from_package(get_package(package))

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\importlib_resources\_common.py:53, in get_package(package)
     47 def get_package(package):
     48     # type: (Package) -> types.ModuleType
     49     """Take a package name or module object and return the module.
     50 
     51     Raise an exception if the resolved module is not a package.
     52     """
---> 53     resolved = resolve(package)
     54     if wrap_spec(resolved).submodule_search_locations is None:
     55         raise TypeError(f'{package!r} is not a package')

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\importlib_resources\_common.py:44, in resolve(cand)
     42 def resolve(cand):
     43     # type: (Package) -> types.ModuleType
---> 44     return cand if isinstance(cand, types.ModuleType) else importlib.import_module(cand)

File ~\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py:126, in import_module(name, package)
    124             break
    125         level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\atari_py\__init__.py:1, in <module>
----> 1 from .ale_python_interface import *
      2 from .games import get_game_path, list_games
      4 # default to only logging errors

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\atari_py\ale_python_interface.py:17, in <module>
     14     ale_lib = cdll.LoadLibrary(os.path.join(os.path.dirname(__file__),
     15                                             'ale_interface/libale_c.so'))
     16 else:
---> 17     ale_lib = cdll.LoadLibrary(os.path.join(os.path.dirname(__file__),
     18                                             'ale_interface/ale_c.dll'))
     20 ale_lib.ALE_new.argtypes = None
     21 ale_lib.ALE_new.restype = c_void_p

File ~\AppData\Local\Programs\Python\Python310\lib\ctypes\__init__.py:452, in LibraryLoader.LoadLibrary(self, name)
    451 def LoadLibrary(self, name):
--> 452     return self._dlltype(name)

File ~\AppData\Local\Programs\Python\Python310\lib\ctypes\__init__.py:374, in CDLL.__init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    371 self._FuncPtr = _FuncPtr
    373 if handle is None:
--> 374     self._handle = _dlopen(self._name, mode)
    375 else:
    376     self._handle = handle

FileNotFoundError: Could not find module 'C:\Users\shiva\AppData\Local\Programs\Python\Python310\lib\site-packages\atari_py\ale_interface\ale_c.dll' (or one of its dependencies). Try using the full path with constructor syntax.

Code:

import gym
from stable_baselines3 import A2C
from stable_baselines3.common.vec_env import VecFrameStack
from stable_baselines3.common.evaluation import evaluate_policy
from stable_baselines3.common.env_util import make_atari_env
from stable_baselines3.common.env_util import make_vec_env

import os
from gym.utils import play
from stable_baselines3.ddpg.policies import CnnPolicy
from ale_py import ALEInterface

ale = ALEInterface()
from ale_py.roms import Breakout

ale.loadROM(Breakout)
env = gym.make('Breakout-v4', render_mode='human')
env = VecFrameStack(make_atari_env("BreakoutNoFrameskip-v4"), n_stack=4)
model = A2C.load(r"C:\Users\shiva\Documents\Atari_Breakout_RL_Project\Training\Logs\BreakoutNoFrameskipv4", env=env)
mean_reward, std_reward = evaluate_policy(model, model.get_env(), n_eval_episodes=10, render=True)

I have also installed the c++ build tools from microsoft's website. i am very confused as the same thing works on my older pc. Please help.

]

System information

bishetheanswer commented 2 years ago

Have you tried it using any other Python versions such us Python 3.7 or 3.8?

Shivam310 commented 2 years ago

Have you tried it using any other Python versions such us Python 3.7 or 3.8?

No as the same thing works on my other computer on 3.10 itself and I don't want to use old version of python as they can cause some problems later on.

endrift commented 2 years ago

This is the repository for Gym Retro, not Gym ALE.