I ran into a couple snags setting up the new machine learning platform released by OpenAI this week so I thought I would publish a quick guide in case anyone ran into similar issues.

Universe lets you run and train AI agents on a growing variety of video games and applications.

Setting up the environment

I chose to run Universe within the Anaconda environment on my computer. This ensures that all the program dependencies are all kept together.

Environment used to install Universe dependencies

Anaconda can be downloaded here.

Anaconda environment download

I downloaded the command-line installer for python 3 and ran it using

bash Anaconda3–4.2.0-MacOSX-x86_64.sh

but you can also use python 2 if you like.

Tip: anaconda is a pretty big program, you can also download miniconda here and run it with bash Miniconda3-latest-Linux-x86_64.sh

I had to add the bin folder to my path by added in line to my .bashrc file.

vim ~/.bashrc

Add export PATH=”$PATH:$HOME/anconda3/bin” # Add anaconda to PATH

Or export PATH=”$PATH:$HOME/miniconda3/bin” # Add minianaconda to PATH

You’ll have to either restart your terminal or re-source by typing source ~/.bashrc to load the addition.

Now you can create an environment to house universe and it’s dependencies. I called mine open-ai .

conda create --name open-ai

Now enter the environment by running source activate open-ai

(Full installation and environment setup instructions)

Dependencies

Instructions for installing all of the software needed to run universe are outlined below.

First make sure you have xcode command line tools installed

xcode-select --install

If you see xcode-select: error: command line tools are already installed, use “Software Update” to install updates you’re good.

I used home brew to install two dependencies. If you don’t have it you can install it with the line

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

To install Universe you will need to install: Go, numpy, incremental, and libjpeg-turbo

pip install numpy incremental

brew install golang libjpeg-turbo

Installation

Now you should have everything you need to install Universe. Go ahead and clone the git repo and install universe using pip.



git clone

cd universe

sudo -H "PATH=$PATH" pip install -e . cd ~/Downloadsgit clone https://github.com/openai/universe.git cd universesudo -H "PATH=$PATH" pip install -e .

Finished installation of universe

Install Docker

One last thing before running our first code, everything in universe runs inside a program called docker so we will need to install this. Download the installer from here.

Download docker page

After running the installer you can launch docker.

Launching docker

Once you get it running you should see it pop up in your menu bar.

Docker running

And typing docker ps should display this output.

Testing docker

Test import of universe

Now everything should be set. To test that universe correctly installed run python in terminal and try to import universe.

python

import universe

Make sure you activated the anaconda environment and then import universe in python

If this does not return an error you’re good.

Run the example code from OpenAI

Copy and save the code below as run.py and run it using python run.py

import gym

import universe # register the universe environments env = gym.make('flashgames.DuskDrive-v0')

env.configure(remotes=1) # automatically creates a local docker container

observation_n = env.reset() while True:

action_n = [[('KeyEvent', 'ArrowUp', True)] for ob in observation_n] # your agent here

observation_n, reward_n, done_n, info = env.step(action_n)

env.render()

save the example code as a python file

save and execute

python run.py

Running the example code

The program will then download a bunch of game content. This will take a while.

It is possible that the download will hang, which was the case for me and is shown in the image below. If this is the case I was able to resolve it by manually downloading the content via docker by running

docker pull quay.io/openai/universe.flashgames:0.20.2

Then rerun the example code any everything should work fine.

Download hangs when you see no change in status for a while

After the download completes the game will launch.

The game running!

Let me know in the comments if you have any issues. I’m glad to help out.

Troubleshooting

Other problems I ran into when installing universe

When installing universe if you are missing dependencies you will see an error such as this. In this case I was missing the golang dependency.

Error thrown when missing dependencies

Error thrown when missing dependencies

Installing universe directly from pip using pip install universe did not work for me and I received the error shown below.