This tutorial will guide you through installing OpenAI's universe on an Ubuntu machine.
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.
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
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
Modify the following code to suit your preferences.
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} cd ${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:
(openai)~$
This lets you know you are using the virtual environment.
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.
echo "UPGRADING PIP" pip install --upgrade pip sudo apt-get update echo "INSTALLING NUMPY AND SCIPY" 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 echo "INSTALLING PANDAS" sudo apt-get install -y python-tk # Needed by Pandas pip install pytz # Needed by pandas pip install pandas # LIBRARIES FOR IMAGE PROCESSING echo "INSTALLING PILLOW IMAGE PROCESSING LIBRARY" sudo apt-get install -y libjpeg-dev libpng12-dev # Needed by pillow pip install Pillow echo 'INSTALL MATPLOTLIB' sudo apt-get build-dep -y matplotlib # build dependencies for matplotlib pip install -U matplotlib # force matplotlib rebuild echo 'INSTALLING ADITIONAL USEFUL PYTHON LIBRARIES' pip install h5py
Not exacly needed by OpenAI, and this is optional, but Tensorflow is great for creating deep learning models.
TF_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl
Now install Tensorflow.
pip install --upgrade $TF_URL
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.
# DEFENDING AGAINST UNMET DEPENDENCIES # First level of defence against potential unmet dependencies errors for # "linux-image-extra-virtual" sudo apt-get -y install -f # INSTALL LINUX-IMAGE-EXTRA-* PACKAGES sudo apt-get install -y linux-image-extra-$(uname -r) # INSTALL LINUX-IMAGE-EXTRA-VIRTUAL PACKAGE # This one could be problematic, see DEBUG section for known issues. sudo apt-get install -y linux-image-extra-virtual
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 https://apt.dockerproject.org/repo ubuntu-xenial main" # 14.04 DK_REPO="deb https://apt.dockerproject.org/repo ubuntu-trusty main"
Adding Docker to the Apt-get repo and keys.
sudo apt-get install -y apt-transport-https ca-certificates # ADD GPG KEY sudo apt-key adv \ --keyserver hkp://ha.pool.sks-keyservers.net:80 \ --recv-keys 58118E89F3A912897C070ADBF76221572C52609D # ADD DOCKER REPO TO THE PACKAGES LIST echo ${DK_REPO} | sudo tee /etc/apt/sources.list.d/docker.list sudo apt-get update
You can either:
# Install the latest version of Docker sudo apt-get install docker-engine
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.
DOCKER_VERSION="1.12.6-0~ubuntu-trusty"
Now, actually install this version of Docker.
# INSTALL DOCKER sudo apt-get -y install docker-engine=${DOCKER_VERSION}
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.
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.
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.
# INSTALL OPENAI UNIVERSE pip install -e git+https://github.com/openai/universe.git#egg=universe
When installing linux-image-extra-virtual
, if you get an error message
such as the following:
linux-image-extra-virtual : Depends: linux-image-generic (= 3.13.0.107.115) but it is not going to be installed E: Unable to correct problems, you have held broken packages.
FIXES:
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.
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 3.13.0.107.115
, then we can force
it to install that version using:
sudo apt-get install linux-image-generic=3.13.0.107.115
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