打开AI Gym:Ant不渲染

问题描述 投票:0回答:1

我无法使用 OpenAIgym 框架渲染蚂蚁。 这是我的代码:

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()

这是我得到的错误: raise AttributeError( AttributeError:意外模式:无,预期模式:人类、rgb_array 或深度_array

我尝试使用虚拟环境,并且已经安装了所有库

python reinforcement-learning openai-gym
1个回答
0
投票

您需要指定渲染模式。所以如果你想渲染这个环境,你可以使用:

env = gym.make("Ant-v4", render_mode='human')
© www.soinside.com 2019 - 2024. All rights reserved.