我会因env渲染而遇到错误-Env.Render()

发布于 2025-01-23 07:55:15 字数 904 浏览 0 评论 0原文

我试图在渲染时实现Atari游戏,如下所示:

line 283, in render
    raise error.Error(
gym.error.Error: render(mode='human') is deprecated. Please supply `render_mode` when constructing your environment, e.g., gym.make(ID, render_mode='human'). The new `render_mode` keyword argument supports DPI scaling, audio, and native framerates.

我获得的完整错误的屏幕截图在这里

我的代码如下:

episodes = 5

for episode in range(1, episodes+1):
state = env.reset()
done = False
score = 0 

while not done:
    env.render()
    action = random.choice([0,1,2,3,4,5])
    n_state, reward, done, info = env.step(action)
    score+=reward
print('Episode:{} Score:{}'.format(episode, score))
env.close()

在堆栈溢出中有类似的帖子,在给出的解决方案中:

pip install pyglet==1.2.4

不幸的是,这也对我不起作用。

I was trying to implement Atari Games while rendering I get an error as given below:

line 283, in render
    raise error.Error(
gym.error.Error: render(mode='human') is deprecated. Please supply `render_mode` when constructing your environment, e.g., gym.make(ID, render_mode='human'). The new `render_mode` keyword argument supports DPI scaling, audio, and native framerates.

Screenshot of the complete error I get is attached here.

My code is given below:

episodes = 5

for episode in range(1, episodes+1):
state = env.reset()
done = False
score = 0 

while not done:
    env.render()
    action = random.choice([0,1,2,3,4,5])
    n_state, reward, done, info = env.step(action)
    score+=reward
print('Episode:{} Score:{}'.format(episode, score))
env.close()

There is a similar post in stack overflow where in the solution given was:

pip install pyglet==1.2.4

Unfortunately this didn't work for me either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神爱温柔 2025-01-30 07:55:15

我一个人弄清楚了。
解决方案是只通过更新render_mode ='human' in env> env> env> env

env = gym.make('SpaceInvaders-v0', render_mode='human')

完整代码:

 import gym
 import random
 import time
 env = gym.make('SpaceInvaders-v0', render_mode='human')
 height, width, channels = env.observation_space.shape
 actions = env.action_space.n
 env.unwrapped.get_action_meanings()
 episodes = 5
 for episode in range(1, episodes+1):
    state = env.reset()
    done = False
    score = 0 
 while not done:
    time.sleep(0.1)
    action = random.choice([0,1,2,3,4,5])
    n_state, reward, done, info = env.step(action)       
    score+=reward
print('Episode:{} Score:{}'.format(episode, score))
env.close()

I have figured it out by myself.
The solution was to just change the environment that we are working by updating render_mode='human' in env:

env = gym.make('SpaceInvaders-v0', render_mode='human')

Full code:

 import gym
 import random
 import time
 env = gym.make('SpaceInvaders-v0', render_mode='human')
 height, width, channels = env.observation_space.shape
 actions = env.action_space.n
 env.unwrapped.get_action_meanings()
 episodes = 5
 for episode in range(1, episodes+1):
    state = env.reset()
    done = False
    score = 0 
 while not done:
    time.sleep(0.1)
    action = random.choice([0,1,2,3,4,5])
    n_state, reward, done, info = env.step(action)       
    score+=reward
print('Episode:{} Score:{}'.format(episode, score))
env.close()
与他有关 2025-01-30 07:55:15

升级Gym为我工作:PIP安装 - 升级健身房

Upgrading gym worked for me: pip install --upgrade gym

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文