{"id":5640,"library":"gym","title":"Gym (OpenAI Gym)","description":"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.","status":"deprecated","version":"0.26.2","language":"python","source_language":"en","source_url":"https://github.com/openai/gym","tags":["reinforcement-learning","rl","environments","ai","deprecated"],"install":[{"cmd":"pip install gym","lang":"bash","label":"Base installation"},{"cmd":"pip install 'gym[atari]' # Example for Atari environments","lang":"bash","label":"With environment extras"},{"cmd":"pip install 'gym[all]' # Install all supported environments","lang":"bash","label":"All environment extras"}],"dependencies":[{"reason":"Fundamental for array operations in observations and actions.","package":"numpy"},{"reason":"Used for serialization of environments.","package":"cloudpickle"},{"reason":"Required for Atari environments","package":"atari_py","optional":true},{"reason":"Required for MuJoCo physics environments","package":"mujoco","optional":true}],"imports":[{"symbol":"gym","correct":"import gym"},{"note":"Many environments have been versioned up (e.g., v1, v2) over time, and older versions may be removed or behave differently.","wrong":"env = gym.make('CartPole-v0')","symbol":"make","correct":"env = gym.make('CartPole-v1')"}],"quickstart":{"code":"import gym\n\nenv = gym.make(\"CartPole-v1\", render_mode=\"human\")\n\n# Reset returns (observation, info) in 0.26.x+\nobservation, info = env.reset(seed=42)\n\nfor _ in range(1000):\n    action = env.action_space.sample()  # Agent selects an action\n    # Step returns (observation, reward, terminated, truncated, info) in 0.26.x+\n    observation, reward, terminated, truncated, info = env.step(action)\n\n    if terminated or truncated:\n        print(f\"Episode finished after {_+1} timesteps.\")\n        observation, info = env.reset(seed=42) # Reset for a new episode\n\nenv.close()","lang":"python","description":"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."},"warnings":[{"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.","message":"The `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.","severity":"breaking","affected_versions":"0.26.2 and earlier"},{"fix":"Update your `step()` calls to unpack 5 values. Use `terminated or truncated` where you previously used `done`.","message":"The `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).","severity":"breaking","affected_versions":"0.26.0+"},{"fix":"Update your `reset()` calls to unpack 2 values: `observation, info = env.reset(...)`. Access additional information from the `info` dictionary.","message":"The `env.reset()` method now returns a 2-tuple: `(observation, info)`. The `return_info` parameter has been removed.","severity":"breaking","affected_versions":"0.26.0+"},{"fix":"Replace `env.seed(my_seed)` with `env.reset(seed=my_seed)` when initializing or restarting an episode.","message":"The `env.seed()` method has been removed. Environment seeding is now handled by passing a `seed` argument to `env.reset()`.","severity":"breaking","affected_versions":"0.26.0+"},{"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.","message":"The `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.","severity":"breaking","affected_versions":"0.26.0+"},{"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.","message":"Many environments require additional dependencies beyond the base `pip install gym`. Attempting to `gym.make()` such an environment without its extras will result in `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.26.2':72 '2022':76 'across':25 'activ':46 'ai':88 'algorithm':24 'api':16,81 'break':80 'chang':82 'collect':28 'compar':20 'deprec':89 'develop':18,50 'divers':27 'drop':61 'drop-in':60 'environ':30,39,87 'former':5 'futur':49 'gym':1,3,4,7,41,69 'gymnasium':58 'histor':34 'introduc':78 'last':65 'learn':22,85 'librari':11,42 'longer':45 'maintain':47 'major':66 'octob':75 'openai':2,6 'provid':13 'python':10 'reinforc':21,84 'reinforcement-learn':83 'releas':67,73 'replac':63 'rl':23,38,86 'signific':79 'standard':36 'successor':57 'support':52 'transit':54 'univers':15 'version':71","created_at":"2026-04-14T03:37:23.977516+00:00","updated_at":"2026-04-16T15:31:08.247054+00:00","problems":[{"fix":"Remove `env.seed(seed)` and pass the seed directly to `env.reset()`. Additionally, `reset()` now returns both an observation and an `info` dictionary.\n```python\n# Old (pre-0.26.0) Gym code\n# env.seed(42)\n# observation = env.reset()\n\n# New (0.26.0+) Gym code\nobservation, info = env.reset(seed=42)\n```","cause":"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.","error":"TypeError: reset() got an unexpected keyword argument 'seed'"},{"fix":"Adjust the unpacking of the `env.step()` return values to accommodate the new `terminated` and `truncated` flags.\n```python\n# Old (pre-0.26.0) Gym code\n# observation, reward, done, info = env.step(action)\n# if done:\n\n# New (0.26.0+) Gym code\nobservation, reward, terminated, truncated, info = env.step(action)\nif terminated or truncated:\n    # Handle episode end\n    pass\n```","cause":"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`.","error":"ValueError: not enough values to unpack (expected 5, got 4)"},{"fix":"Install the `gym` library using pip. If using a virtual environment, ensure it's activated before installation.\n```bash\npip install gym\n```","cause":"The `gym` package is not installed in the Python environment being used, or the environment is not correctly activated.","error":"ModuleNotFoundError: No module named 'gym'"},{"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').\n```python\n# For custom environments, ensure the module registering it is imported\nimport my_custom_gym_envs # Assuming this module contains the gym.register() call\n\nenv = gym.make('MyCustomEnv-v0') # Use the exact registered ID\n```","cause":"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.","error":"gym.error.UnregisteredEnv: No registered env with id: Env-v0"},{"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.\n```bash\npip uninstall numpy\npip install numpy==1.23.5\n\n# Or, migrate to gymnasium\npip install gymnasium\n# Then update your code to import gymnasium as gym and adapt to its API if necessary\n```","cause":"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.","error":"AttributeError: module 'numpy' has no attribute 'bool8'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.26.2","cli_name":"","cli_version":null,"type":"library","homepage":"https://www.gymlibrary.dev/","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/gym/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-30","next_check":"2026-07-28","install_tag":null}}