O'Reilly logo

Artificial Intelligence with Python by Prateek Joshi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating an environment

We will be using a package called OpenAI Gym to build reinforcement learning agents. You can learn more about it here: https://gym.openai.com . We can install it using pip by running the following command on the Terminal:

$ pip3 install gym

You can find various tips and tricks related to its installation here: https://github.com/openai/gym#installation . Now that you have installed it, let's go ahead and write some code.

Create a new python file and import the following package:

import argparse 
 
import gym 

Define a function to parse the input arguments. We will be able to specify the type of environment we want to run:

def build_arg_parser(): parser = argparse.ArgumentParser(description='Run an environment') parser.add_argument('--input-env', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required