how to solve module 'gym.wrappers' has no attribute 'Monitor'?
Asked Answered
A

2

7

import gym

if __name__ == "__main__":
    env = gym.make("CartPole-v0")
    env = gym.wrappers.Monitor(env, "recording")

    total_reward = 0.0
    total_steps = 0
    obs = env.reset()

    while True:
        action = env.action_space.sample()
        obs, reward, done, _ = env.step(action)
        total_reward += reward
        total_steps += 1
        if done:
            break

    print("Episode done in %d steps, total reward %.2f" % (
        total_steps, total_reward))
    env.close()
    env.env.close()

these codes are from :Maxim Lapan. Deep Reinforcement Learning Hands-On

when i run these code,i get this:'gym.wrappers' has no attribute 'Monitor'

i try to search on google to find answer,but i still have no idea about the way to solve the question.

Adequate answered 9/3, 2022 at 14:35 Comment(0)
B
8

it looks like they've changed the API and removed the 'Monitor'-wrapper (https://github.com/openai/gym/releases/tag/0.23.0).

You could either use the version of 'gym' from the book (0.15.3) (e.g. pip install gym==0.15.3) or you could use the render()-method of the updated environment class (from v0.23.0).

In the latter case you'd need to include env.render() into the while-loop:

    while True:
        action = env.action_space.sample()
        obs, reward, done, _ = env.step(action)
        total_reward += reward
        total_steps += 1
        env.render()
        if done:
            break
Breakable answered 12/3, 2022 at 15:21 Comment(0)
K
3

Use this

from gym.wrappers.monitoring.video_recorder import VideoRecorder

how to use it can be found here https://www.anyscale.com/blog/an-introduction-to-reinforcement-learning-with-openai-gym-rllib-and-google

Krisha answered 26/11, 2022 at 19:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.