Setting up our machine
In this section, we will learn how to install several dependencies that are required for running the code used throughout the book. First, we will learn how to install Anaconda and then we will explore how to install Gym.
Installing Anaconda
Anaconda is an open-source distribution of Python. It is widely used for scientific computing and processing large volumes of data. It provides an excellent package management environment, and it supports Windows, Mac, and Linux operating systems. Anaconda comes with Python installed, along with popular packages used for scientific computing such as NumPy, SciPy, and so on.
To download Anaconda, visit https://www.anaconda.com/download/, where you will see an option for downloading Anaconda for different platforms. If you are using Windows or macOS, you can directly download the graphical installer according to your machine architecture and install Anaconda using the graphical installer.
If you are using Linux, follow these steps:
- Open the Terminal and type the following command to download Anaconda:
wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
- After downloading, we can install Anaconda using the following command:
bash Anaconda3-5.0.1-Linux-x86_64.sh
After the successful installation of Anaconda, we need to create a virtual environment. What is the need for a virtual environment? Say we are working on project A, which uses NumPy version 1.14, and project B, which uses NumPy version 1.13. So, to work on project B we either downgrade NumPy or reinstall NumPy. In each project, we use different libraries with different versions that are not applicable to the other projects. Instead of downgrading or upgrading versions or reinstalling libraries every time for a new project, we use a virtual environment.
The virtual environment is just an isolated environment for a particular project so that each project can have its own dependencies and will not affect other projects. We will create a virtual environment using the following command and name our environment universe
:
conda create --name universe python=3.6 anaconda
Note that we use Python version 3.6. Once the virtual environment is created, we can activate it using the following command:
source activate universe
That's it! Now that we have learned how to install Anaconda and create a virtual environment, in the next section, we will learn how to install Gym.
Installing the Gym toolkit
In this section, we will learn how to install the Gym toolkit. Before going ahead, first, let's activate our virtual environment, universe
:
source activate universe
Now, install the following dependencies:
sudo apt-get update
sudo apt-get install golang libcupti-dev libjpeg-turbo8-dev make tmux htop chromium-browser git cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev python-opengl libboost-all-dev libsdl2-dev swig
conda install pip six libgcc swig
conda install opencv
We can install Gym directly using pip
. Note that throughout the book, we will use Gym version 0.15.4. We can install Gym using the following command:
pip install gym==0.15.4
We can also install Gym by cloning the Gym repository as follows:
cd ~
git clone https://github.com/openai/gym.git
cd gym
pip install -e '.[all]'
Common error fixes
Just in case, if you get any of the following errors while installing Gym, the following commands will help:
- Failed building wheel for pachi-py or failed building wheel for pachi-py atari-py:
sudo apt-get update sudo apt-get install xvfb libav-tools xorg-dev libsdl2-dev swig cmake
- Failed building wheel for mujoco-py:
git clone https://github.com/openai/mujoco-py.git cd mujoco-py sudo apt-get update sudo apt-get install libgl1-mesa-dev libgl1-mesa-glx libosmesa6-dev python3-pip python3-numpy python3-scipy pip3 install -r requirements.txt sudo python3 setup.py install
- error: command 'gcc' failed with exit status 1:
sudo apt-get update sudo apt-get install python-dev sudo apt-get install libevent-dev
Now that we have successfully installed Gym, in the next section, let's kickstart our hands-on reinforcement learning journey.