openai / gym

A toolkit for developing and comparing reinforcement learning algorithms.
https://www.gymlibrary.dev
Other
34.2k stars 8.58k forks source link

env.render() doesn't open any window #3233

Open tanishqackerman opened 12 months ago

tanishqackerman commented 12 months ago

I am a beginner in RL and running env.render() doesn't open any environment window, please help.

environment_name = "CartPole-v1" env = gym.make(environment_name) episodes = 5 for episode in range(1, episodes + 1): state = env.reset() done = False score = 0

while not done:
    env.render()
    action = env.action_space.sample()
    n_state, reward, done, truncated, info = env.step(action)
    score += reward
print(f"Episode {episode} Score {score}")

env.close()

pseudo-rnd-thoughts commented 12 months ago

For the latest gym version, please see the example here - https://gymnasium.farama.org/

tanishqackerman commented 12 months ago

Okay, so should I use gymnasium instead of gym or are they both the same thing?

And also one more help, can you tell how to install packages like stable-baselines[extra], gymnasium[box2d] because installing them using pip shows no package found, I mean packages with square brackets [ ].

please help, just a beginner

pseudo-rnd-thoughts commented 11 months ago

Gymnasium is a maintained version of Gym pip install "stable-baselines[extra]" should be all you require

tetrapod0 commented 2 weeks ago

I realized I had to just change it.

before

import gymnasium as gym
env = gym.make("LunarLander-v2")

after

import gymnasium as gym
env = gym.make("LunarLander-v2", render_mode="human")