Arcade Learning Environment (ale-py)
ale-py is the Python interface to the Arcade Learning Environment (ALE), a platform for AI research built on the Atari 2600 emulator Stella. It allows researchers to develop and test AI agents for Atari games, abstracting away emulation details. The library is currently at version 0.11.2, actively maintained by the Farama Foundation, and has a steady release cadence incorporating updates like Gymnasium integration and ROM packaging.
Common errors
-
No module named 'ale_py._ale_py' (or similar ModuleNotFoundError when importing gym)
cause This often occurs when `ale-py`'s internal C++ bindings are not correctly compiled or located, or when Gymnasium environments are used without properly registering `ale_py`.fixEnsure `ale-py` is installed correctly, possibly in a fresh virtual environment. For Gymnasium, you *must* explicitly `import ale_py` and then call `gymnasium.register_envs(ale_py)` before creating any Atari environments with `gym.make()`. -
ERROR: Could not find a version that satisfies the requirement ale-py (from versions: none) / ERROR: No matching distribution found for ale-py
cause This error typically indicates that your Python version is not supported by the available `ale-py` wheels on PyPI, or your `pip` is outdated.fixUpgrade `pip` (`pip install --upgrade pip`). If the error persists, check `ale-py`'s PyPI page for supported Python versions and consider using a compatible Python version (e.g., Python 3.9-3.11 for older `ale-py`, or `ale-py` >=0.9.0 for Python 3.12+). -
game_env = gym.make('Pong-v4') fails with a ROM error or environment not foundcause Older `gym` versions required manual ROM installation or `gym[atari,accept-rom-license]`. With Gymnasium, the environment registration is often missed, or a very old `ale-py` is used that doesn't include ROMs.fixEnsure you are using `gymnasium` and `ale-py >=0.9.0`. Explicitly import `ale_py` and then call `gymnasium.register_envs(ale_py)` *before* `gym.make()`. If using `pip install "gymnasium[atari]"`, ROMs should be automatically handled. If you need custom ROMs, use `ale-import-roms /path/to/roms` or set `ALE_ROM_DIR`.
Warnings
- breaking Starting with ale-py v0.9.0, the library transitioned from supporting OpenAI Gym to Gymnasium (>= 1.0.0a1). The `gym` package is no longer maintained, and `ale-py` uses Gymnasium as the sole backend environment. This requires adapting code that used the older `gym` API.
- breaking Atari ROMs are now packaged directly within the `ale-py` PyPI installation since v0.9.0, eliminating the need for `pip install "gym[accept-rom-license]"` or the `ale-import-roms` tool for standard ROMs. However, custom or additional ROMs can still be managed via `ale-import-roms` or by setting the `ALE_ROM_DIR` environment variable.
- deprecated Direct importing of `atari-py roms` (e.g., `import ale_py.roms as roms` to get external ROMs) will not be supported in future releases of `ale-py` for external ROM handling.
- gotcha Older versions of `ale-py` might not have wheels available for the latest Python versions (e.g., Python 3.12 prior to `ale-py` v0.9.0). This can lead to installation failures.
- gotcha When using Gymnasium environments, the `env.render()` method is generally discouraged in favor of supplying the `render_mode` keyword argument during environment initialization for improved rendering capabilities (frame-perfect, audio, scaling).
Install
-
pip install ale-py -
pip install "gymnasium[atari]"
Imports
- ALEInterface
from ale_py._ale_py import ALEInterface
from ale_py import ALEInterface
- roms
import ale_py.roms
from ale_py import roms
- register_envs (Gymnasium)
import gymnasium as gym env = gym.make('ALE/Breakout-v5')import gymnasium as gym import ale_py gym.register_envs(ale_py)
Quickstart
import gymnasium as gym
import ale_py
from ale_py import ALEInterface, roms
# --- Direct ALEInterface usage ---
ale = ALEInterface()
# ROMs are now packaged within ale-py, access via roms.get_rom_path
ale.loadROM(roms.get_rom_path("breakout"))
ale.reset_game()
reward = ale.act(0) # Perform a 'noop' action
screen_obs = ale.getScreenRGB()
print(f"Direct ALE: Initial reward: {reward}, Screen shape: {screen_obs.shape}")
ale.close()
# --- Gymnasium integration ---
# Register ALE environments with Gymnasium
gym.register_envs(ale_py)
env = gym.make('ALE/Breakout-v5', render_mode='rgb_array')
obs, info = env.reset()
print(f"Gymnasium: Initial observation shape: {obs.shape}")
action = env.action_space.sample() # Take a random action
obs, reward, terminated, truncated, info = env.step(action)
print(f"Gymnasium: Step reward: {reward}, Terminated: {terminated}, Truncated: {truncated}")
env.close()