analitics

Pages

Showing posts with label gym. Show all posts
Showing posts with label gym. Show all posts

Monday, April 11, 2022

Python 3.7.8 : Gym toolkit - part 001.

Today I tested the gym python package and both version of python: 3.7.8 and 3.10.4.
Gym is a toolkit for developing and comparing reinforcement learning algorithms. It supports teaching agents everything from walking to playing games like Pong or Pinball.
pip install gym
...
Successfully installed cloudpickle-2.0.0 gym-0.23.1 gym-notices-0.0.6 importlib-
metadata-4.11.3 numpy-1.21.5 typing-extensions-4.1.1 zipp-3.8.0
C:\Python378>pip install Pygame
...
Successfully installed Pygame-2.1.2
C:\Python378>python.exe
Python 3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 08:53:46) [MSC v.1916 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import gym
You can see the gym python package is loaded.
Let's test the default python source code from the official webpage:
import gym
env = gym.make("CartPole-v1")
observation = env.reset()
for _ in range(1000):
  env.render()
  action = env.action_space.sample() # your agent here (this takes random actions)
  observation, reward, done, info = env.step(action)

  if done:
    observation = env.reset()
env.close()
I created a file name gym001.py and I run it with python.exe.
The result is a window like on the official webpage.
I tested with python version 3.10.4 with same example and works well:
C:\Python310>python.exe -m pip install gym
...
Installing collected packages: gym-notices, numpy, cloudpickle, gym
Successfully installed cloudpickle-2.0.0 gym-0.23.1 gym-notices-0.0.6 numpy-1.22.3
C:\Python310>python.exe -m pip install pygame
...
Successfully installed pygame-2.1.2
C:\Python310>python.exe gym001.py
...