Registry / ai-ml / gym
library0.26.2pypypi✓ verified 21d ago

Gym (formerly OpenAI Gym) is a Python library that provided a universal API for developing and comparing reinforcement learning (RL) algorithms across a diverse collection of environments. While it was historically the standard for RL environments, the `gym` library is no longer actively maintained. All future development and support have transitioned to its successor, `gymnasium`, a drop-in replacement. The last major release of `gym` was version 0.26.2, released in October 2022, which introduced significant breaking API changes.

pip install gym
INSTALL
IMPORT
SIG · GYM
G
gym
ai-mlpythonv0.26.2
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.26.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
1/3 runs
2/3 runs
py 3.11
1/3 runs
2/3 runs
py 3.12
1/3 runs
1/3 runs
py 3.13
1/3 runs
1/3 runs
py 3.9
1/3 runs
2/3 runs
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

gym
import gym
make
env = gym.make('CartPole-v1')
env = gym.make('CartPole-v0')
Many environments have been versioned up (e.g., v1, v2) over time, and older versions may be removed or behave differently.

This example demonstrates how to create a CartPole-v1 environment, reset it with a seed, take random actions, and handle the new 5-tuple return value from `step()` and 2-tuple from `reset()` in Gym 0.26.x+. The environment is rendered to a human-viewable window.

import gym env = gym.make("CartPole-v1", render_mode="human") # Reset returns (observation, info) in 0.26.x+ observation, info = env.reset(seed=42) for _ in range(1000): action = env.action_space.sample() # Agent selects an action # Step returns (observation, reward, terminated, truncated, info) in 0.26.x+ observation, reward, terminated, truncated, info = env.step(action) if terminated or truncated: print(f"Episode finished after {_+1} timesteps.") observation, info = env.reset(seed=42) # Reset for a new episode env.close()
Debug
Known issues
breakingThe `gym` library is no longer maintained; all future development and support have moved to `gymnasium`. Users are strongly encouraged to migrate to `gymnasium` for continued updates, bug fixes, and compatibility with modern Python and NumPy versions.
fix
Migrate your code to use `gymnasium`. The API is largely a drop-in replacement with `import gymnasium as gym`, but review `gymnasium` migration guides for version-specific changes, especially if upgrading from older `gym` versions.
affects: 0.26.2 and earlier
breakingThe `env.step()` method now returns a 5-tuple: `(observation, reward, terminated, truncated, info)`. The old `done` flag is split into `terminated` (agent's action led to termination) and `truncated` (e.g., time limit reached).
fix
Update your `step()` calls to unpack 5 values. Use `terminated or truncated` where you previously used `done`.
affects: 0.26.0+
breakingThe `env.reset()` method now returns a 2-tuple: `(observation, info)`. The `return_info` parameter has been removed.
fix
Update your `reset()` calls to unpack 2 values: `observation, info = env.reset(...)`. Access additional information from the `info` dictionary.
affects: 0.26.0+
breakingThe `env.seed()` method has been removed. Environment seeding is now handled by passing a `seed` argument to `env.reset()`.
fix
Replace `env.seed(my_seed)` with `env.reset(seed=my_seed)` when initializing or restarting an episode.
affects: 0.26.0+
breakingThe `render_mode` should be specified during `gym.make()` (e.g., `gym.make('Env-v1', render_mode='human')`) and is no longer passed to the `env.render()` method.
fix
Provide `render_mode` when creating the environment with `gym.make()`. The `env.render()` method should then be called without arguments if rendering is enabled.
affects: 0.26.0+
gotchaMany environments require additional dependencies beyond the base `pip install gym`. Attempting to `gym.make()` such an environment without its extras will result in `ModuleNotFoundError`.
fix
Install the necessary environment extras, e.g., `pip install 'gym[atari]'` for Atari environments, or `pip install 'gym[mujoco]'` for MuJoCo environments. Use `pip install 'gym[all]'` for all extras, though this can be substantial.
affects: All versions
Errors
Common errors & fixes
TypeError: reset() got an unexpected keyword argument 'seed'
In Gym version 0.26.0 and later, the `env.seed()` method was deprecated, and environment seeding is now handled by passing the `seed` argument directly to the `env.reset()` method.
fix
Remove `env.seed(seed)` and pass the seed directly to `env.reset()`. Additionally, `reset()` now returns both an observation and an `info` dictionary.
```python
# Old (pre-0.26.0) Gym code
# env.seed(42)
# observation = env.reset()

# New (0.26.0+) Gym code
observation, info = env.reset(seed=42)
```
ValueError: not enough values to unpack (expected 5, got 4)
Gym version 0.26.0 introduced breaking API changes where the `env.step()` method now returns five values instead of the previous four, separating the `done` flag into `terminated` and `truncated`.
fix
Adjust the unpacking of the `env.step()` return values to accommodate the new `terminated` and `truncated` flags.
```python
# Old (pre-0.26.0) Gym code
# observation, reward, done, info = env.step(action)
# if done:

# New (0.26.0+) Gym code
observation, reward, terminated, truncated, info = env.step(action)
if terminated or truncated:
    # Handle episode end
    pass
```
ModuleNotFoundError: No module named 'gym'
The `gym` package is not installed in the Python environment being used, or the environment is not correctly activated.
fix
Install the `gym` library using pip. If using a virtual environment, ensure it's activated before installation.
```bash
pip install gym
```
gym.error.UnregisteredEnv: No registered env with id: Env-v0
This error occurs when `gym.make()` is called for an environment ID that has not been properly registered within the Gym registry. This often happens with custom environments if their registration code (e.g., in an `__init__.py` file) hasn't been imported or executed, or if the environment ID is misspelled.
fix
Ensure that the custom environment's registration code is imported or the package containing it is installed in 'editable' mode (`pip install -e .`). For built-in environments, verify the ID's exact spelling, including any versioning (e.g., 'CartPole-v1').
```python
# For custom environments, ensure the module registering it is imported
import my_custom_gym_envs # Assuming this module contains the gym.register() call

env = gym.make('MyCustomEnv-v0') # Use the exact registered ID
```
AttributeError: module 'numpy' has no attribute 'bool8'
This issue arises from an incompatibility between `gym` version 0.26.2 and newer versions of the NumPy library (e.g., NumPy 2.0.0+), where `np.bool8` was removed or changed.
fix
Downgrade NumPy to a compatible version (e.g., `numpy==1.23.5`) or migrate to the `gymnasium` library, which is the actively maintained successor to `gym` and is compatible with newer NumPy versions.
```bash
pip uninstall numpy
pip install numpy==1.23.5

# Or, migrate to gymnasium
pip install gymnasium
# Then update your code to import gymnasium as gym and adapt to its API if necessary
```
Upgrade
Version history
0.26.2latest on PyPI · released Oct 4, 2022
Audit
Dependencies
numpyrequiredFundamental for array operations in observations and actions.
cloudpicklerequiredUsed for serialization of environments.
atari_pyoptionalRequired for Atari environments
mujocooptionalRequired for MuJoCo physics environments
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
gym — pip install gym · libregistry