Gymnasium provides a standard API for reinforcement learning environments, offering a diverse set of reference environments for research and development. It is the spiritual successor to OpenAI Gym, maintained by the Farama Foundation, and receives frequent minor releases with bug fixes, new features, and API improvements. The current version is 1.2.3.
pip install gymnasiumVerified import paths — ran on the pinned version, not inferred.
Initializes a CartPole-v1 environment, steps through it for 100 timesteps using random actions, and resets when the episode terminates or truncates. Demonstrates the modern `render_mode` parameter, the `seed` argument for `reset()`, and the split `terminated`/`truncated` flags from `step()`.
Replace `import gym` with `import gymnasium as gym` (or similar) in all your code.
Update calls from `obs = env.reset()` to `obs, info = env.reset()` and adjust your code to handle the `info` dictionary.
Update calls from `obs, reward, done, info = env.step(action)` to `obs, reward, terminated, truncated, info = env.step(action)`. Adjust logic from `if done:` to `if terminated or truncated:`.
When calling `gymnasium.make()`, include `render_mode="rgb_array"`, `render_mode="human"`, or `render_mode=None` as appropriate for your use case.
Install `gymnasium-robotics` (`pip install gymnasium-robotics`) and update environment IDs if you rely on these specific MuJoCo versions. For modern MuJoCo environments (v4), use `gymnasium[mujoco]`.
Ensure `pip install gymnasium[box2d]` or manually install `box2d` if managing dependencies yourself. Do not rely on `box2d-py` for `gymnasium` versions 1.2.3 and later.
Run `pip install gymnasium` in your terminal to install the library.
If you intend to use Gymnasium, change `import gym` to `import gymnasium as gym` and ensure 'gymnasium' is installed with `pip install gymnasium`.
Install the Atari dependencies for Gymnasium using `pip install "gymnasium[atari, accept-rom-license]"`.
Ensure you are consistently using Gymnasium by importing `import gymnasium as gym` and verify that the environment ID and API calls (e.g., `env.reset(seed=...)` and `env.step(...)` returning `(observation, reward, terminated, truncated, info)`) are compliant with Gymnasium's API (version 0.26.0 and higher). If you specifically need legacy OpenAI Gym behavior, consider using a separate virtual environment with the older `gym` package.