运行代码:
import gym
def cartpole():
environment = gym.make('CartPole-v1')
environment.reset()
for _ in range(1000):
environment.render()
action = environment.action_space.sample()
observation, reward, done, info = environment.step(action)
print("Step {}:".format(_))
print("action: {}".format(action))
print("observation: {}".format(observation))
print("reward: {}".format(reward))
print("done: {}".format(done))
print("info: {}".format(info))
if __name__ == '__main__':
cartpole()
报错,提示需要安装pyglet:
安装pyglet:
pip install pyglet
再次运行依然报错:
最后发现其原因在pyglet的版本问题:
卸载pyglet并重新安装即可解决:
pip uninstall pyglet
pip install pyglet==1.2.4
成功解决错误。