Simple Setup of OpenAI Gym on MacOS

Andrew Schreiber
2 min readApr 17, 2017

--

LunarLander-V1 environment

OpenAI Gym is a toolkit for testing reinforcement learning algorithms. Gym is fun and powerful, but installation can be a challenge. This post will give you a one-line command to install Gym on any modern Mac, reducing your setup time to minutes.

To get started, open up terminal and run the below command to download and run the setup script:

bash <(curl -Ls https://raw.githubusercontent.com/andrewschreiber/scripts/master/gym_installer.sh)

That’s it! The script will take a few minutes to interactively install Gym and it’s dependencies as seen below.

Check out the source code

How It Works

[Step 1] Homebrew — MacOS Package manager

We use Homebrew to install Gym’s system-level dependencies. Homebrew downloads packages to their own folders, and uses symlinks to make the commands available. Here’s a summary of each dependency:

cmake: Cross-platform build tool.

swig: Call C/C++ interfaces from Python.

boost: Powerful additions to C++ standard library

boost-python: Python wrapper for boost.

sdl2: Provides low-level, cross-platform access to graphics hardware

wget: Easily download files

We also install the Xcode Command Line tools, which is needed for compiling certain environments.

[Step 2] Conda — Environment and package manager

Conda (also known by Anaconda or Miniconda) is an alternative to the pip/virtualenv/easy_install toolchain. Conda makes it easy to setup Python 3.5 and by using a Conda environment existing python setups will not be affected.

[Step 3] Install OpenAI Gym

We install Gym using pip within our Conda environment called ‘p36’. Here are the library dependencies:

numpy: Scientific computing

request: HTTP requests

six: Python 2 & 3 compatibility

pyglet: Windowing and graphics

keras: High-level neural network API

theano: Deep Learning & matrix math integrated with numpy

atari_py: High-performance hooks into emulated games

Pillow: Image processing

PyOpenGL: Call OpenGL APIs with Python

box2d-py: 2D game physics simulator

pachi-py: Play Go programmatically

mujoco_py: Qwop-like physics simulations

imageio: Image reading/writing

[Step 4] Test an agent.

We create a ‘GymAgents’ folder in the current directory to place our Python-based agents.

Then we download and run a simple example agent to make sure Gym has been successfully installed. If everything works, you will see a ASCII message like this:

If you run into any challenges with the setup script, let me know via the comment section or preferably Github issues. My goal is to make the script as fast, clear, and enjoyable as possible.

You now should be setup with OpenAI Gym. Read the docs and test your Reinforcement Learning algorithms!

--

--