OpenAI Gym is an open-source Python library specifically designed for developing and comparing reinforcement learning algorithms. It connects learning algorithms and environments through a standardized API and provides a collection of environments that conform to this API standard. Since its release, the Gym API has become a standard in the field of reinforcement learning.
Project Maintenance Status Change: The team that has been maintaining Gym since 2021 has transferred all future development efforts to Gymnasium, which is a direct replacement for Gym (usable with import gymnasium as gym
). Gym will no longer receive any future updates, and users are advised to switch to Gymnasium as soon as possible.
pip install gym
# Install Atari environment dependencies
pip install gym[atari]
# Install all environment dependencies
pip install gym[all]
# Install MuJoCo environment dependencies (latest version)
pip install gym[mujoco]
# Install MuJoCo environment dependencies (older version)
pip install gym[mujoco_py]
import gym
# Create environment
env = gym.make("CartPole-v1")
# Reset environment
observation, info = env.reset(seed=42)
# Environment interaction loop
for _ in range(1000):
# Randomly select action
action = env.action_space.sample()
# Execute action
observation, reward, terminated, truncated, info = env.step(action)
# Check if reset is needed
if terminated or truncated:
observation, info = env.reset()
# Close environment
env.close()
CleanRL - Learning library based on the Gym API
Tianshou - Learning library for experienced users
RLlib - Learning library that supports distributed training
PettingZoo - Multi-agent environment library
Gym employs strict version control to ensure reproducibility:
mujoco-py
mujoco
as a required dependencyThe project whitepaper is available on arXiv, citation format:
@misc{1606.01540,
Author = {Greg Brockman and Vicki Cheung and Ludwig Pettersson and Jonas Schneider and John Schulman and Jie Tang and Wojciech Zaremba},
Title = {OpenAI Gym},
Year = {2016},
Eprint = {arXiv:1606.01540},
}
OpenAI Gym, as a pioneering tool in the field of reinforcement learning, has established industry standards and fostered a vast ecosystem. Although the original project is no longer actively maintained, its successor, Gymnasium, inherits all core functionalities, ensuring the continued development of the community. For new projects, it is strongly recommended to use Gymnasium directly to obtain the latest features and ongoing support.