Install and Setup OpenAI

This tutorial will guide you through installing OpenAI's universe on an Ubuntu machine.


  • This tutorial assumes you are using either Ubuntu 14.04 or 16.04. But you might be able to modify things to work on a different version.
  • You already have Python 2.7 or 3.5 installed on your system.
  • You are familiar with how to use the command line.

Automated Option

I have created a shell script which automates the entire installation process described below.

So you could just run that script and skip this lesson on installing OpenAI Universe. If you decide to run the script instead, then make sure you read the README file on the Github page, as you may need to modify the values of some variables.

But be sure to come back and continue with the next lesson on Starting with OpenAI.

Also be sure to check out the debugging section in case you encounter one of the common errors.


Many of the steps are based on code from the following sources, but put together here in one convenient and guided way.


Installing Dependencies

Run the following lines on the command line to install some of the dependencies.

# Update package database
sudo apt-get update
sudo apt-get upgrade

# Developer Libraries
sudo apt-get install build-essential git  swig

# Needed for Open AI
sudo apt-get install golang libjpeg-turbo8-dev make

Get the pip python package instaler.

sudo apt-get install python-pip python-dev python-wheel 

Setting up a Virtual Environment (Optional)

Install virtualenv package

This is an optional, but highly recomended step. You can create a Python virtual environment to keep the python libraries you install for this project separate from other projects to avoid conflicts with version numbers, and to protect against other changes that might cause conflict with other packages you rely on for other projects.

To install virtualenv run the following command.

sudo apt-get install python-virtualenv

Creating a new Virtual Environment

Modify the following code to suit your preferences.

  • Chose Python version: Specify the version of Python you want to make use of. Note that OpenAI Universe currently only supports Python 2.7 and 3.5, so chose either of these that is instaled on your system.
  • Virtualenv Direcory: You will need to chose where you want to store your virtual environments. It should be some directory that you can easily navigate to on the command line.
  • Virtualenv Name: a name for your new virtual environment. This will end up creating a new directory in your virtualenvs directory.
PYTHON_VERSION="2.7"              # Change this to 3.5 if desired.
VIRTUAL_ENV_NAME="openai"         # Name you want to give your virtualenv
VIRTUAL_ENV_ROOT="~/virtualenvs"  # NOTE: no forward slash at end

Now create the new virtual environment by running the following.

mkdir -p ${VIRTUAL_ENV_ROOT}
virtualenv -p /usr/bin/python${PYTHON_VERSION} ${VIRTUAL_ENV_NAME}

Now to start making use of the virtualenv:

source ${VIRTUAL_ENV_ROOT}/${VIRTUAL_ENV_NAME}/bin/activate

The start of your command line should now look something like this:


This lets you know you are using the virtual environment.

Setting up python dependencies

Not all of the following python libraries are necessary for OpenAI to run, but they are useful if you plan on doing machine learning with it.

pip install --upgrade pip
sudo apt-get update

sudo apt-get install -y libopenblas-dev        # Speeds up numpy/scipy
sudo apt-get install -y liblapack-dev gfortran # Needed for scipy/numpy
pip install numpy
pip install scipy 

sudo apt-get install -y python-tk  # Needed by Pandas
pip install pytz                   # Needed by pandas
pip install pandas

sudo apt-get install -y libjpeg-dev libpng12-dev    # Needed by pillow
pip install Pillow

sudo apt-get build-dep -y matplotlib # build dependencies for matplotlib
pip install -U matplotlib            # force matplotlib rebuild

pip install h5py

Installing Tensorflow

Not exacly needed by OpenAI, and this is optional, but Tensorflow is great for creating deep learning models.

  • Tensorflow URL: Get the URL to the version of tensorflow you want to use from here. Below i made use of v0.12 for python 2.7 CPU only. Get a different URL if you wish to use a different version, or one that supports a different version of python, Or if you wish to have GPU support.

Now install Tensorflow.

pip install --upgrade $TF_URL

Installing Kernel Dependencies for Docker

Note: This set of steps might be the most problematic ones, especially intalling the linux-image-extra-virtual package. See the debugging section if you run into problems here.

# First level of defence against potential unmet dependencies errors for
# "linux-image-extra-virtual"
sudo apt-get -y install -f

sudo apt-get install -y linux-image-extra-$(uname -r)

# This one could be problematic, see DEBUG section for known issues.
sudo apt-get install -y linux-image-extra-virtual

Preparing Docker Repository

The following line is not needed for ubuntu 16.04, but might be needed for older verions. Ubuntu 14.04: requires this step.

# This next line needed for ubuntu 14.04, but not needed for 16.04
sudo add-apt-repository ppa:ubuntu-lxc/lxd-stable  # for newer golang

Now run only ONE of the following steps to set the variable that will store the repo for your OS. See here for the repo to use for other Ubuntu versions.

# 16.04
DK_REPO="deb ubuntu-xenial main"

# 14.04
DK_REPO="deb ubuntu-trusty main"

Adding Docker to the Apt-get repo and keys.

sudo apt-get install -y apt-transport-https ca-certificates

sudo apt-key adv \
               --keyserver hkp:// \
               --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

echo ${DK_REPO} | sudo tee /etc/apt/sources.list.d/docker.list

sudo apt-get update

Installing Docker

You can either:

  • Install latest version of Docker (easy)
  • or specific version of Docker (recomended for production environment)

Install Latest Version of Docker

# Install the latest version of Docker
sudo apt-get install docker-engine

Install Specific Version of Docker

You can get a list of the available versions of Docker on your operating system by running the following command.

# Get list of available versions on apt-get
apt-cache madison docker-engine

One of the columns of printout will have output like this: 1.12.6-0~ubuntu-trusty (or 1.12.6-0~ubuntu-xenial). Select a version you want to make use of and change the variable value below to the chosen value, then run it on the command line.


Now, actually install this version of Docker.

sudo apt-get -y install docker-engine=${DOCKER_VERSION}

Checking Docker is Installed Properly

Run the following commands to check if Docker is installed properly.

sudo service docker start
sudo docker run hello-world

If you get the following message, then it is installed correctly.

Hello from Docker!
This message shows that your installation appears to be working correctly.

Adding Current User to Docker Group

You will need to grant the current user the rights to access the Docker group. These steps were taken from here.

sudo groupadd -f docker
sudo gpasswd -a ${USER} docker
newgrp docker

You will now need to reboot your system to make the user priveleges take effect.

Once you have rebooted, run the following in the command line.

docker ps

You should now see some output that looks like this:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

If not, then the current user has not been added to the Docker group properly. You will need to try again. OpenAI will not run if you cannot get your user to get access to the Docker group.

Installing OpenAI Universe

You will want to go back into the virtualenv you created previously. Use the following (substituting for where you located your virtualenv.

source ~/virtualens/openai/bin/activate

Now, we can finally install the OpenAI Universe.

pip install -e git+



When installing linux-image-extra-virtual, if you get an error message such as the following:

linux-image-extra-virtual : Depends: linux-image-generic (=
but it is not going to be installed
E: Unable to correct problems, you have held broken packages.


  1. Run the following command:

    sudo apt-get -y install -f

    Then pick up where you left off before. If this gives the same error message, then try the next fix.

  2. The error message tells you that it is looking for a version of linux-image-generic, but is not finding it installed, and not wanting to install it either. You can explicitly install this version on the command line. Lets say the version it was looking for was, then we can force it to install that version using:

    sudo apt-get install linux-image-generic=

    NOTE: Make sure you change the number to the version that the error message was telling you to use.

Also note that DOcker requires a linux kernel >= 3.13