我在_render函数中得到了常见pygame.error: display Surface quit
,如下所示。健身房环境运行,但在大约10秒后崩溃。我是pygame的新手,所以如果解释错误会有所帮助。我已经检查了here和here,但答案并没有解决我的问题。完整代码为here。当我通过我的main.py文件运行程序时程序与健身房成功运行,但是当我使用gym_test.py运行它时,我得到了错误。
main.py
def main():
game = Frogger(visual=False)
while True:
# self.game_data = game.load_sprites()
action = game.action_space.sample()
_, _, terminal, _ = game.step(action)
if terminal:
game.reset()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if __name__ == '__main__':
main()
gym_test.py
import gym
import gym_audio
import pygame
env = gym.make('Frogger-v0')
for i_episode in range(20):
observation = env.reset()
for t in range(100):
env.render()
print(observation)
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
if done:
print("Episode finished after {} timesteps".format(t+1))
pygame.quit()
break
render.py
def _render(self, mode='human', close=False):
self.screen.blit(self.background, (0, 0))
sys.exitfunc中的错误: Traceback(最近一次调用最后一次): 文件“/usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py”, 第24行,在_run_exitfuncs中 func(* targs,** kargs) 文件“/usr/local/lib/python2.7/site-packages/gym/utils/closer.py”,第67行, 在附近 closeable.close() 文件“/usr/local/lib/python2.7/site-packages/gym/core.py”,第164行,关闭 self.render(接近= TRUE) 文件“/usr/local/lib/python2.7/site-packages/gym/core.py”,第150行,渲染 return self._render(mode = mode,close = close) 文件“/Users/lusenii/Developer/gym-audio/gym_audio/envs/frogger.py”,行 82,在_render self.screen.blit(self.background,(0,0)) pygame.error:显示表面退出