Angad Sandhu
Search
Browse
On this page

breakout-v5

Using Deep Reinforcement Learning to create an RL intelligent agent that can Balance a Pole on a moving Cart

https://www.gymlibrary.dev/environments/atari/breakout/

Importing Libraries

# base libs
import gymnasium as gym
import numpy as np
import random
FileNotFoundError: Could not find module 'c:\Python310\lib\site-packages\atari_py\ale_interface\ale_c.dll' (or one of its dependencies). Try using the full path with constructor syntax.
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[1], line 2
      1 # base libs
----> 2 import gymnasium as gym
      3 import numpy as np
      4 import random

File c:\Python310\lib\site-packages\gymnasium\__init__.py:12
      4 from gymnasium.core import (
      5     Env,
      6     Wrapper,
   (...)
      9     RewardWrapper,
     10 )
     11 from gymnasium.spaces.space import Space
---> 12 from gymnasium.envs.registration import make, spec, register, registry, pprint_registry
     13 from gymnasium import envs, spaces, utils, vector, wrappers, error, logger, experimental
     16 __all__ = [
     17     # core classes
     18     "Env",
   (...)
     38     "experimental",
     39 ]

File c:\Python310\lib\site-packages\gymnasium\envs\__init__.py:352
    344 register(
    345     id="HumanoidStandup-v4",
    346     entry_point="gymnasium.envs.mujoco.humanoidstandup_v4:HumanoidStandupEnv",
    347     max_episode_steps=1000,
    348 )
    351 # Hook to load plugins from entry points
--> 352 load_env_plugins()

File c:\Python310\lib\site-packages\gymnasium\envs\registration.py:309, in load_env_plugins(entry_point)
    303         logger.warn(
    304             f"The environment namespace magic key `{plugin.name}` is unsupported. "
    305             "To register an environment at the root namespace you should specify the `__root__` namespace."
    306         )
    308 with context:
--> 309     fn = plugin.load()
    310     try:
    311         fn()

File c:\Python310\lib\importlib\metadata\__init__.py:162, in EntryPoint.load(self)
    157 """Load the entry point from its definition. If only a module
    158 is indicated by the value, return that module. Otherwise,
    159 return the named object.
    160 """
    161 match = self.pattern.match(self.value)
--> 162 module = import_module(match.group('module'))
    163 attrs = filter(None, (match.group('attr') or '').split('.'))
    164 return functools.reduce(getattr, attrs, module)

File c:\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 c:\Python310\lib\site-packages\shimmy\__init__.py:7
      4 from typing import Any
      6 from shimmy.dm_lab_compatibility import DmLabCompatibilityV0
----> 7 from shimmy.openai_gym_compatibility import GymV22CompatibilityV0, GymV26CompatibilityV0
      9 __version__ = "0.2.0"
     12 class NotInstallClass:

File c:\Python310\lib\site-packages\shimmy\openai_gym_compatibility.py:34
     30     from typing_extensions import Protocol, runtime_checkable
     33 try:
---> 34     import gym
     35     import gym.wrappers
     36 except ImportError as e:

File c:\Python310\lib\site-packages\gym\__init__.py:13
      4 from gym.core import (
      5     Env,
      6     GoalEnv,
   (...)
     10     RewardWrapper,
     11 )
     12 from gym.spaces import Space
---> 13 from gym.envs import make, spec, register
     14 from gym import logger
     15 from gym import vector

File c:\Python310\lib\site-packages\gym\envs\__init__.py:10
      1 from gym.envs.registration import (
      2     registry,
      3     register,
   (...)
      6     load_env_plugins as _load_env_plugins,
      7 )
      9 # Hook to load plugins from entry points
---> 10 _load_env_plugins()
     13 # Classic
     14 # ----------------------------------------
     16 register(
     17     id="CartPole-v0",
     18     entry_point="gym.envs.classic_control:CartPoleEnv",
     19     max_episode_steps=200,
     20     reward_threshold=195.0,
     21 )

File c:\Python310\lib\site-packages\gym\envs\registration.py:276, in load_env_plugins(entry_point)
    271         logger.warn(
    272             f"Trying to register an internal environment when `{module}` is not in the whitelist"
    273         )
    275 with context:
--> 276     fn = plugin.load()
    277     try:
    278         fn()

File c:\Python310\lib\importlib\metadata\__init__.py:162, in EntryPoint.load(self)
    157 """Load the entry point from its definition. If only a module
    158 is indicated by the value, return that module. Otherwise,
    159 return the named object.
    160 """
    161 match = self.pattern.match(self.value)
--> 162 module = import_module(match.group('module'))
    163 attrs = filter(None, (match.group('attr') or '').split('.'))
    164 return functools.reduce(getattr, attrs, module)

File c:\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\Roaming\Python\Python310\site-packages\ale_py\gym.py:5
      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\Roaming\Python\Python310\site-packages\ale_py\roms\__init__.py:89
     85     return roms
     88 # Resolve all ROMs
---> 89 ROMS = resolve_roms()
     90 __all__ = list(ROMS.keys())
     93 def __dir__() -> List[str]:

File ~\AppData\Roaming\Python\Python310\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\Roaming\Python\Python310\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 c:\Python310\lib\site-packages\importlib_resources\_common.py:46, in package_to_anchor.<locals>.wrapper(anchor, package)
     44 elif anchor is undefined:
     45     return func()
---> 46 return func(anchor)

File c:\Python310\lib\site-packages\importlib_resources\_common.py:56, in files(anchor)
     51 @package_to_anchor
     52 def files(anchor: Optional[Anchor] = None) -> Traversable:
     53     """
     54     Get a Traversable resource for an anchor.
     55     """
---> 56     return from_package(resolve(anchor))

File c:\Python310\lib\functools.py:878, in singledispatch.<locals>.wrapper(*args, **kw)
    874 if not args:
    875     raise TypeError(f'{funcname} requires at least '
    876                     '1 positional argument')
--> 878 return dispatch(args[0].__class__)(*args, **kw)

File c:\Python310\lib\site-packages\importlib_resources\_common.py:82, in _(cand)
     80 @resolve.register
     81 def _(cand: str) -> types.ModuleType:
---> 82     return importlib.import_module(cand)

File c:\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 c:\Python310\lib\site-packages\atari_py\__init__.py:1
----> 1 from .ale_python_interface import *
      2 from .games import get_game_path, list_games
      4 # default to only logging errors

File c:\Python310\lib\site-packages\atari_py\ale_python_interface.py:17
     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 c:\Python310\lib\ctypes\__init__.py:452, in LibraryLoader.LoadLibrary(self, name)
    451 def LoadLibrary(self, name):
--> 452     return self._dlltype(name)

File c:\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:\Python310\lib\site-packages\atari_py\ale_interface\ale_c.dll' (or one of its dependencies). Try using the full path with constructor syntax.
import gymnasium as gym
import time
import numpy as np
import matplotlib.pyplot as plt
import ale_py
from ale_py import ALEInterface
from gym import envs
AttributeError: partially initialized module 'gym' has no attribute 'core' (most likely due to a circular import)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 1
----> 1 import gymnasium as gym
      2 import time
      3 import numpy as np

File c:\Python310\lib\site-packages\gymnasium\__init__.py:12
      4 from gymnasium.core import (
      5     Env,
      6     Wrapper,
   (...)
      9     RewardWrapper,
     10 )
     11 from gymnasium.spaces.space import Space
---> 12 from gymnasium.envs.registration import make, spec, register, registry, pprint_registry
     13 from gymnasium import envs, spaces, utils, vector, wrappers, error, logger, experimental
     16 __all__ = [
     17     # core classes
     18     "Env",
   (...)
     38     "experimental",
     39 ]

File c:\Python310\lib\site-packages\gymnasium\envs\__init__.py:352
    344 register(
    345     id="HumanoidStandup-v4",
    346     entry_point="gymnasium.envs.mujoco.humanoidstandup_v4:HumanoidStandupEnv",
    347     max_episode_steps=1000,
    348 )
    351 # Hook to load plugins from entry points
--> 352 load_env_plugins()

File c:\Python310\lib\site-packages\gymnasium\envs\registration.py:309, in load_env_plugins(entry_point)
    303         logger.warn(
    304             f"The environment namespace magic key `{plugin.name}` is unsupported. "
    305             "To register an environment at the root namespace you should specify the `__root__` namespace."
    306         )
    308 with context:
--> 309     fn = plugin.load()
    310     try:
    311         fn()

File c:\Python310\lib\importlib\metadata\__init__.py:162, in EntryPoint.load(self)
    157 """Load the entry point from its definition. If only a module
    158 is indicated by the value, return that module. Otherwise,
    159 return the named object.
    160 """
    161 match = self.pattern.match(self.value)
--> 162 module = import_module(match.group('module'))
    163 attrs = filter(None, (match.group('attr') or '').split('.'))
    164 return functools.reduce(getattr, attrs, module)

File c:\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 c:\Python310\lib\site-packages\shimmy\__init__.py:7
      4 from typing import Any
      6 from shimmy.dm_lab_compatibility import DmLabCompatibilityV0
----> 7 from shimmy.openai_gym_compatibility import GymV22CompatibilityV0, GymV26CompatibilityV0
      9 __version__ = "0.2.0"
     12 class NotInstallClass:

File c:\Python310\lib\site-packages\shimmy\openai_gym_compatibility.py:34
     30     from typing_extensions import Protocol, runtime_checkable
     33 try:
---> 34     import gym
     35     import gym.wrappers
     36 except ImportError as e:

File c:\Python310\lib\site-packages\gym\__init__.py:16
     14 from gym import logger
     15 from gym import vector
---> 16 from gym import wrappers
     18 __all__ = ["Env", "Space", "Wrapper", "make", "spec", "register"]

File c:\Python310\lib\site-packages\gym\wrappers\__init__.py:17
     15 from gym.wrappers.clip_action import ClipAction
     16 from gym.wrappers.record_episode_statistics import RecordEpisodeStatistics
---> 17 from gym.wrappers.normalize import NormalizeObservation, NormalizeReward
     18 from gym.wrappers.record_video import RecordVideo, capped_cubic_video_schedule

File c:\Python310\lib\site-packages\gym\wrappers\normalize.py:41
     36     new_count = tot_count
     38     return new_mean, new_var, new_count
---> 41 class NormalizeObservation(gym.core.Wrapper):
     42     def __init__(
     43         self,
     44         env,
     45         epsilon=1e-8,
     46     ):
     47         super(NormalizeObservation, self).__init__(env)

AttributeError: partially initialized module 'gym' has no attribute 'core' (most likely due to a circular import)

Creating Enviournment

ale = ALEInterface()

env_name = 'Breakout-v4'
env = gym.make(env_name)
from ale_py import ALEInterface
import gym
env = gym.make('SpaceInvaders-v0')
env.reset()
for _ in range(1000):
    env.step(env.action_space.sample())
    env.render('human')
env.close() 
FileNotFoundError: Could not find module 'c:\Python310\lib\site-packages\atari_py\ale_interface\ale_c.dll' (or one of its dependencies). Try using the full path with constructor syntax.
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[1], line 1
----> 1 import gym
      2 env = gym.make('SpaceInvaders-v0')
      3 env.reset()

File c:\Python310\lib\site-packages\gym\__init__.py:13
      4 from gym.core import (
      5     Env,
      6     GoalEnv,
   (...)
     10     RewardWrapper,
     11 )
     12 from gym.spaces import Space
---> 13 from gym.envs import make, spec, register
     14 from gym import logger
     15 from gym import vector

File c:\Python310\lib\site-packages\gym\envs\__init__.py:10
      1 from gym.envs.registration import (
      2     registry,
      3     register,
   (...)
      6     load_env_plugins as _load_env_plugins,
      7 )
      9 # Hook to load plugins from entry points
---> 10 _load_env_plugins()
     13 # Classic
     14 # ----------------------------------------
     16 register(
     17     id="CartPole-v0",
     18     entry_point="gym.envs.classic_control:CartPoleEnv",
     19     max_episode_steps=200,
     20     reward_threshold=195.0,
     21 )

File c:\Python310\lib\site-packages\gym\envs\registration.py:276, in load_env_plugins(entry_point)
    271         logger.warn(
    272             f"Trying to register an internal environment when `{module}` is not in the whitelist"
    273         )
    275 with context:
--> 276     fn = plugin.load()
    277     try:
    278         fn()

File c:\Python310\lib\importlib\metadata\__init__.py:162, in EntryPoint.load(self)
    157 """Load the entry point from its definition. If only a module
    158 is indicated by the value, return that module. Otherwise,
    159 return the named object.
    160 """
    161 match = self.pattern.match(self.value)
--> 162 module = import_module(match.group('module'))
    163 attrs = filter(None, (match.group('attr') or '').split('.'))
    164 return functools.reduce(getattr, attrs, module)

File c:\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\Roaming\Python\Python310\site-packages\ale_py\gym.py:5
      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\Roaming\Python\Python310\site-packages\ale_py\roms\__init__.py:89
     85     return roms
     88 # Resolve all ROMs
---> 89 ROMS = resolve_roms()
     90 __all__ = list(ROMS.keys())
     93 def __dir__() -> List[str]:

File ~\AppData\Roaming\Python\Python310\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\Roaming\Python\Python310\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 c:\Python310\lib\site-packages\importlib_resources\_common.py:46, in package_to_anchor.<locals>.wrapper(anchor, package)
     44 elif anchor is undefined:
     45     return func()
---> 46 return func(anchor)

File c:\Python310\lib\site-packages\importlib_resources\_common.py:56, in files(anchor)
     51 @package_to_anchor
     52 def files(anchor: Optional[Anchor] = None) -> Traversable:
     53     """
     54     Get a Traversable resource for an anchor.
     55     """
---> 56     return from_package(resolve(anchor))

File c:\Python310\lib\functools.py:878, in singledispatch.<locals>.wrapper(*args, **kw)
    874 if not args:
    875     raise TypeError(f'{funcname} requires at least '
    876                     '1 positional argument')
--> 878 return dispatch(args[0].__class__)(*args, **kw)

File c:\Python310\lib\site-packages\importlib_resources\_common.py:82, in _(cand)
     80 @resolve.register
     81 def _(cand: str) -> types.ModuleType:
---> 82     return importlib.import_module(cand)

File c:\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 c:\Python310\lib\site-packages\atari_py\__init__.py:1
----> 1 from .ale_python_interface import *
      2 from .games import get_game_path, list_games
      4 # default to only logging errors

File c:\Python310\lib\site-packages\atari_py\ale_python_interface.py:17
     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 c:\Python310\lib\ctypes\__init__.py:452, in LibraryLoader.LoadLibrary(self, name)
    451 def LoadLibrary(self, name):
--> 452     return self._dlltype(name)

File c:\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:\Python310\lib\site-packages\atari_py\ale_interface\ale_c.dll' (or one of its dependencies). Try using the full path with constructor syntax.

Browse the library