Hands-On Intelligent Agents with OpenAI Gym
上QQ阅读APP看书,第一时间看更新

Prerequisites

The only main prerequisite for using OpenAI Gym is Python 3.5+. To make further development easy and organized, we will use the Anaconda Python distribution. For those of you who are not familiar with Anaconda, it is a Python distribution (although a distribution for the R language is also available) that includes hundreds of popular machine learning and data science packages and comes with an easy-to-use package and virtual environment manager called conda. The good thing is that the Anaconda Python distribution is available for Linux, macOS, and Windows! Another main reason to use the Anaconda distribution is that it helps in easily creating, installing, managing, and upgrading an isolated Python virtual environment. This makes sure the code we learn about and develop in this book produces the same results, irrespective of the operating system we use. This will relieve you from solving dependency issues or library version mismatch issues that you would have had to handle manually if you were not using a Python distribution such as Anaconda. You will find that it just works, which is nice and cool. Let's get started and install the Anaconda Python distribution.

Open a command prompt or Terminal and enter the following:

praveen@ubuntu:~$wget http://repo.continuum.io/archive/Anaconda3-4.3.0-Linux-x86_64.sh -O ~/anaconda.sh

This command uses the wget tool to fetch/download the installation script for Anaconda version 3-4.3 and saves it as anaconda.sh in your home directory. This command should work on macOS and Linux (Ubuntu, Kubuntu, and so on), which come with the wget tool pre-installed. Note that we are downloading a specific version of Anaconda (3-4.3). This will make sure we have the same configuration throughout this book. Do not worry if this is not the latest version available. You can always upgrade the distribution later using this command:

conda update conda

anaconda.sh is a shell script that has all the things that are needed to install Anaconda on your system! If you are interested, you can open it using your favorite text editor to see how cleverly the binaries, the installation process instructions, and the shell commands have been all lumped together into a single file.

Let's now install the Anaconda Python distribution under your home directory. The following installation process is carefully laid out to make sure it works both on Linux and macOS systems. Before you enter the command, you should be aware of one thing. The following command will run the installer in silent mode. This means that it will use the default installation parameters and go ahead with the installation, without asking you yes/no for each and every configuration. This also means that you agree to the Anaconda distribution's licensing terms. In case you want to manually go through the installation process step by step, run the following command without the arguments -b and -f:

praveen@ubuntu:~$bash ~/anaconda.sh -b -f -p $HOME/anaconda

Wait for the installation process to complete and then we are done!

To start using conda and the other goodness in the Anaconda Python distribution, we should make sure that your system knows where to find the Anaconda tools. Let's add the Anaconda binaries directory by appending its path to the PATH environment variable, as shown here:

praveen@ubuntu:~$export PATH=$HOME/anaconda/bin:$PATH

I strongly advise you to add this line to the end of your ~/.bashrc file so that whenever you open a new bash terminal, the Anaconda tools are accessible.

 You can type the following command to make sure the installation was successful:

praveen@ubuntu:~$conda list

This command will just print the list of packages available in your default environment.