In [4]:
%matplotlib inline
import gym
import numpy as np
from matplotlib import pyplot as plt
In [6]:
env = gym.envs.make("Breakout-v0")
print("Action space size: {}".format(env.action_space.n))
print(env.get_action_meanings())
observation = env.reset()
print("Observation space shape: {}".format(observation.shape))
plt.figure()
plt.imshow(env.render(mode='rgb_array'))
[env.step(2) for x in range(1)]
plt.figure()
plt.imshow(env.render(mode='rgb_array'))
env.render(close=True)
[2017-03-08 21:13:15,268] Making new env: Breakout-v0
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/home/yunjey/anaconda3/lib/python3.5/site-packages/gym/envs/atari/atari_env.py in <module>()
8 try:
----> 9 import atari_py
10 except ImportError as e:
ImportError: No module named 'atari_py'
During handling of the above exception, another exception occurred:
DependencyNotInstalled Traceback (most recent call last)
<ipython-input-6-fd0311e5e366> in <module>()
----> 1 env = gym.envs.make("Breakout-v0")
2
3 print("Action space size: {}".format(env.action_space.n))
4 print(env.get_action_meanings())
5
/home/yunjey/anaconda3/lib/python3.5/site-packages/gym/envs/registration.py in make(id)
159
160 def make(id):
--> 161 return registry.make(id)
162
163 def spec(id):
/home/yunjey/anaconda3/lib/python3.5/site-packages/gym/envs/registration.py in make(self, id)
117 logger.info('Making new env: %s', id)
118 spec = self.spec(id)
--> 119 env = spec.make()
120 if (env.spec.timestep_limit is not None) and not spec.tags.get('vnc'):
121 from gym.wrappers.time_limit import TimeLimit
/home/yunjey/anaconda3/lib/python3.5/site-packages/gym/envs/registration.py in make(self)
83 raise error.Error('Attempting to make deprecated env {}. (HINT: is there a newer registered version of this env?)'.format(self.id))
84
---> 85 cls = load(self._entry_point)
86 env = cls(**self._kwargs)
87
/home/yunjey/anaconda3/lib/python3.5/site-packages/gym/envs/registration.py in load(name)
15 def load(name):
16 entry_point = pkg_resources.EntryPoint.parse('x={}'.format(name))
---> 17 result = entry_point.load(False)
18 return result
19
/home/yunjey/anaconda3/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg/pkg_resources/__init__.py in load(self, require, *args, **kwargs)
2256 if require:
2257 self.require(*args, **kwargs)
-> 2258 return self.resolve()
2259
2260 def resolve(self):
/home/yunjey/anaconda3/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg/pkg_resources/__init__.py in resolve(self)
2262 Resolve the entry point from its module and attrs.
2263 """
-> 2264 module = __import__(self.module_name, fromlist=['__name__'], level=0)
2265 try:
2266 return functools.reduce(getattr, self.attrs, module)
/home/yunjey/anaconda3/lib/python3.5/site-packages/gym/envs/atari/__init__.py in <module>()
----> 1 from gym.envs.atari.atari_env import AtariEnv
/home/yunjey/anaconda3/lib/python3.5/site-packages/gym/envs/atari/atari_env.py in <module>()
9 import atari_py
10 except ImportError as e:
---> 11 raise error.DependencyNotInstalled("{}. (HINT: you can install Atari dependencies by running 'pip install gym[atari]'.)".format(e))
12
13 import logging
DependencyNotInstalled: No module named 'atari_py'. (HINT: you can install Atari dependencies by running 'pip install gym[atari]'.)
In [5]:
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
[2017-03-08 21:12:44,474] Making new env: CartPole-v0
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-5-3093026983cb> in <module>()
4 observation = env.reset()
5 for t in range(100):
----> 6 env.render()
7 print(observation)
8 action = env.action_space.sample()
/home/yunjey/anaconda3/lib/python3.5/site-packages/gym/core.py in render(self, mode, close)
155 elif mode not in modes:
156 raise error.UnsupportedMode('Unsupported rendering mode: {}. (Supported modes for {}: {})'.format(mode, self, modes))
--> 157 return self._render(mode=mode, close=close)
158
159 def close(self):
/home/yunjey/anaconda3/lib/python3.5/site-packages/gym/core.py in _render(self, mode, close)
285
286 def _render(self, mode='human', close=False):
--> 287 return self.env.render(mode, close)
288
289 def _close(self):
/home/yunjey/anaconda3/lib/python3.5/site-packages/gym/core.py in render(self, mode, close)
155 elif mode not in modes:
156 raise error.UnsupportedMode('Unsupported rendering mode: {}. (Supported modes for {}: {})'.format(mode, self, modes))
--> 157 return self._render(mode=mode, close=close)
158
159 def close(self):
/home/yunjey/anaconda3/lib/python3.5/site-packages/gym/envs/classic_control/cartpole.py in _render(self, mode, close)
112
113 if self.viewer is None:
--> 114 from gym.envs.classic_control import rendering
115 self.viewer = rendering.Viewer(screen_width, screen_height)
116 l,r,t,b = -cartwidth/2, cartwidth/2, cartheight/2, -cartheight/2
/home/yunjey/anaconda3/lib/python3.5/site-packages/gym/envs/classic_control/rendering.py in <module>()
21
22 try:
---> 23 from pyglet.gl import *
24 except ImportError as e:
25 reraise(prefix="Error occured while running `from pyglet.gl import *`",suffix="HINT: make sure you have OpenGL install. On Ubuntu, you can run 'apt-get install python-opengl'. If you're running on a server, you may need a virtual frame buffer; something like this should work: 'xvfb-run -s \"-screen 0 1400x900x24\" python <your_script.py>'")
/home/yunjey/anaconda3/lib/python3.5/site-packages/pyglet/gl/__init__.py in <module>()
222 else:
223 from .carbon import CarbonConfig as Config
--> 224 del base
225
226 # XXX remove
NameError: name 'base' is not defined
In [ ]:
Content source: trhongbinwang/data_science_journey
Similar notebooks: