Completing the OpenAI Gym setup
Let's update our version of pip first:
(rl_gym_book) praveen@ubuntu:~$ pip install --ignore-installed pip
Then, let's download the source code of OpenAI Gym from the GitHub repository into our home folder:
(rl_gym_book) praveen@ubuntu:~$cd ~
(rl_gym_book) praveen@ubuntu:~$git clone https://github.com/openai/gym.git
(rl_gym_book) praveen@ubuntu:~$cd gym
We are now in the final stage of a complete Gym installation! If you got a MuJoCo license and followed the MuJoCo installation instructions successfully, then you can go ahead and complete a full installation by running the following command:
(rl_gym_book) praveen@ubuntu:~/gym$pip install -e '.[all]'
If you did not install MuJoCo, then this command will return errors. We will be installing the Gym environments that we will be using, other than MuJoCo (which requires a license to use). Make sure that you are still in the gym directory under your home folder, and also make sure that you are still inside the rl_gym_book conda environment. Your prompt should include the rl_gym_book prefix as follows, where ~/gym means that the prompt is at the gym directory under the home folder:
(rl_gym_book) praveen@ubuntu:~/gym$
Here is a table summarizing the installation commands for installing the environments that have been discussed in Chapter 1, Introduction to Intelligent Agents and Learning Environments.
Environment Installation command
Atari pip install -e '.[atari]'
Box2D
pip install -e '.[box2d]'
conda install -c https://conda.anaconda.org/kne pybox2d
Classic control
pip install -e '.[classic_control]'
MuJoCo (requires license) pip install -e '.[mujoco]'
Robotics (requires license)
pip install -e '.[robotics]'
Let's go ahead and install the environments we do not need a license to use. Run the following commands to install Atarti, Box2D, and the classic control environments:
(rl_gym_book) praveen@ubuntu:~/gym$pip install -e '.[atari]'
(rl_gym_book) praveen@ubuntu:~/gym$pip install -e '.[box2d]'
(rl_gym_book) praveen@ubuntu:~/gym$conda install -c https://conda.anaconda.org/kne pybox2d
(rl_gym_book) praveen@ubuntu:~/gym$pip install -e '.[classic_control]'
We are all set! We'll quickly run a check to make sure the installation went fine. Copy and paste the following code snippet into a file named test_box2d.py under the ~/rl_gym_book directory:
#!/usr/bin/env python
import gym
env = gym.make('BipedalWalker-v2')
env.reset()
for _ in range(1000):
env.render()
env.step(env.action_space.sample())
Run that code using the following commands:
(rl_gym_book) praveen@ubuntu:~/gym$cd ~/rl_gym_book
(rl_gym_book) praveen@ubuntu:~/rl_gym_book$python test_box2d.py
You will see a window pop up that shows the BipedalWalker-v2 environment and the walker trying to randomly perform some actions:
So, we have the Gym environment set up. What's next, you may ask. In the next section, we will set up the tools and libraries we need to develop deep reinforcement learning agents to train in these environments!