open ai gym Nameerror

匿名 (未验证) 提交于 2019-12-03 08:50:26

问题:

I am trying to use the famous 'Gym' module from OpenAI on WSL and executing code on python 3.5.2. When I try to run an environment as explained here, using the code:

import gym env = gym.make('CartPole-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))             break 

this happens :

Traceback (most recent call last):   File "<stdin>", line 4, in <module>   File "/home/DrHofstadter/gym/gym/core.py", line 153, in render     return self._render(mode=mode, close=close)   File "/home/DrHofstadter/gym/gym/core.py", line 285, in _render     return self.env.render(mode, close)   File "/home/DrHofstadter/gym/gym/core.py", line 153, in render     return self._render(mode=mode, close=close)   File "/home/DrHofstadter/gym/gym/envs/classic_control/cartpole.py", line 114, in _render     from gym.envs.classic_control import rendering   File "/home/DrHofstadter/gym/gym/envs/classic_control/rendering.py", line 23, in <module>     from pyglet.gl import *   File "/home/DrHofstadter/.local/lib/python3.5/site-packages/pyglet/gl/__init__.py", line 224, in <module>     del base NameError: name 'base' is not defined 

The problem is similar to this question nothing is being rendered. (The gitterforum link given in question doesn't work anymore.)

回答1:

I was using an Ubuntu 16.04 VM with python 3.5.2. Here's how I installed and ran OpenAI gym on it. (Reference: https://github.com/openai/gym#installing-everything)

sudo apt-get install cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev libboost-all-dev libsdl2-dev swig sudo apt-get install python3-dev python3-future sudo pip3 install numpy sudo pip3 install PyOpenGL sudo pip3 install piglet sudo pip3 install pyglet mkdir -p ~/src cd ~/src git clone https://github.com/openai/gym cd gym python3 ./setup.py clean sudo pip3 install -e '.[all]' 

I'd then verify the installation by import gym in python3.

Here's what I got when I ran the CartPole-v0 demo.



文章来源: open ai gym Nameerror
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!