How to install OpenAI Gym

Rodolfo Mendes
3 min readMay 24, 2019

--

The OpenAI/Gym project offers a common interface for different kinds of environments so we can focus on creating and testing our reinforcement learning models. In this tutorial, I show how to install Gym using the most common package managers for Python.

Prerequisites

The only prerequisite for basic installation of Gym is the Python 3.5+ interpreter and its package manager pip. Environments like Atari, Retro or MuJoCo have additional requirements.

pip

The easiest way to install the Gym library is by using the pip tool. In order to install the latest version of Gym all you have to do is execute the command:

pip install gym

For some Linux distributions and for MacOS the default Python commands points to a default installation of Python 2. If that’s the case, execute the Python 3 version of pip:

pip3 install gym

And that’s it. Also, if you want to install Gym with the latest merge, you can install it directly from its source code. You do that by cloning the Gym repository from Github and executing pip right away:

git clone https://github.com/openai/gym cd gym pip install -e .

(Don’t forget the dot at the end of last command)

By installing Gym using the default package, the following environments will be available for you:

Additional environments like Atari or MuJoCo must be installed separately, as they have dependencies that are not included with the default package.

pipenv

If you use pipenv to manage the dependencies of your projects, the process to install Gym using pipenv is very similar. Just execute the following command inside your project:

pipenv install gym

conda

Another option is install Gym using the conda package manager, although the available packages at conda repositories are not officially supported by the Gym team. You can install Gym using conda executing the following command:

conda install -c akode gym

The option -c akode indicates the channel in which conda must search for the gym package.

The steps to install Gym are very simple. However, additional environments may depend on native or proprietary dependencies that must be manually installed which can cause some hassle. For that reason, I recommend you install the basic packages first and then add new environments incrementally.

So, if even after following these steps you can’t execute gym or if you have any difficult on installing and executing a Gym environment, feel free to contact me at questions@reinforcementelearning4.fun and I will be very glad to help you.

Software engineer for more than 10 years, I help developers to apply Reinforcement Learning and Deep Learning to create game bots, so they can have fun! View all posts by Rodolfo Mendes

Published

Originally published at http://reinforcementlearning4.fun on May 24, 2019.

--

--

Rodolfo Mendes
Rodolfo Mendes

Written by Rodolfo Mendes

I help machine learning engineers to deploy, monitor, and scale machine learning models, so they don't have to work overtime.