Open AI Gym: Ant not rendering

256 Views Asked by At

I have been unable to render the ant using the OpenAI gym framework. Here is my code:

import gymnasium as gym

env = gym.make("Ant-v4")

# Reset the environment to start a new episode
observation = env.reset()

for _ in range(1000):
    # Render the environment
    env.render()

    # Take a random action
    action = env.action_space.sample()
    observation, reward, done, info = env.step(action)

    if done:
        # Reset the environment if the episode is done
        observation = env.reset()

# Close the environment
env.close()

And this is the error that I get raise AttributeError( AttributeError: Unexpected mode: None, expected modes: human, rgb_array, or depth_array

I have tried to use a virtual environment and I have installed all the libraries.

1

There are 1 best solutions below

2
On

You need to specify a render mode. So if you want to render this environment, you would use:

env = gym.make("Ant-v4", render_mode='human')