I am trying to get the window to render showing me the game running but it never pops up and just finishes running printing out the 5 scores. I am not sure if there is a problem in vs code (I m running on my machine I am not using a virtual environment)
here is the code
import os
import gym
from stable_baselines3 import PPO
from stable_baselines3.common.vec_env import DummyVecEnv
from stable_baselines3.common.evaluation import evaluate_policy
env_name = 'CartPole-v1'
env = gym.make(env_name, render_mode="rgb_array")
episodes = 5
for episode in range(episodes+1):
state = env.reset()
done = False
score = 0
while not done:
env.render()
action = env.action_space.sample()
n_state, reward, done, info, k = env.step(action)
score += reward
print('Episode: {} Score: {}'.format(episode, score))
env.close()
I have tried different environments such as a virtual environment and google collab but nothing gets this window to render for a visual look at what's happening
You could either do one of two things:
render_mode
tohuman
. Depending on thegym
version, you either have to callenv.render()
to update the frame or it is done automatically for you. So:env = gym.make(env_name, render_mode="human")