In [2]:
#!/usr/bin/env python
from __future__ import print_function

import sys, gym

#
# Test yourself as a learning agent! Pass environment name as a command-line argument.
#

# env = gym.make('LunarLander-v2' if len(sys.argv)<2 else sys.argv[1])

env = gym.make('LunarLander-v2')


if not hasattr(env.action_space, 'n'):
    raise Exception('Keyboard agent only supports discrete action spaces')
ACTIONS = env.action_space.n
ROLLOUT_TIME = 1000
SKIP_CONTROL = 0    # Use previous control decision SKIP_CONTROL times, that's how you
                    # can test what skip is still usable.

human_agent_action = 0
human_wants_restart = False
human_sets_pause = False

def key_press(key, mod):
    global human_agent_action, human_wants_restart, human_sets_pause
    if key==0xff0d: human_wants_restart = True
    if key==32: human_sets_pause = not human_sets_pause
    a = int( key - ord('0') )
    if a <= 0 or a >= ACTIONS: return
    human_agent_action = a

def key_release(key, mod):
    global human_agent_action
    a = int( key - ord('0') )
    if a <= 0 or a >= ACTIONS: return
    if human_agent_action == a:
        human_agent_action = 0

env.render()
env.unwrapped.viewer.window.on_key_press = key_press
env.unwrapped.viewer.window.on_key_release = key_release

def rollout(env):
    global human_agent_action, human_wants_restart, human_sets_pause
    human_wants_restart = False
    obser = env.reset()
    skip = 0
    for t in range(ROLLOUT_TIME):
        if not skip:
            #print("taking action {}".format(human_agent_action))
            a = human_agent_action
            skip = SKIP_CONTROL
        else:
            skip -= 1

        obser, r, done, info = env.step(a)
        env.render()
        if done: break
        if human_wants_restart: break
        while human_sets_pause:
            env.render()
            import time
            time.sleep(0.1)

print("ACTIONS={}".format(ACTIONS))
print("Press keys 1 2 3 ... to take actions 1 2 3 ...")
print("No keys pressed is taking action 0")

while 1:
    rollout(env)


[2017-03-05 13:10:47,564] Making new env: LunarLander-v2
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-ffa66f289e3d> in <module>()
     10 # env = gym.make('LunarLander-v2' if len(sys.argv)<2 else sys.argv[1])
     11 
---> 12 env = gym.make('LunarLander-v2')
     13 
     14 

/home/ge/projects/deep_learning_notes/Proj_Neural_Programmer_Interpreter/gym/gym/envs/registration.py in make(id)
    159 
    160 def make(id):
--> 161     return registry.make(id)
    162 
    163 def spec(id):

/home/ge/projects/deep_learning_notes/Proj_Neural_Programmer_Interpreter/gym/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/ge/projects/deep_learning_notes/Proj_Neural_Programmer_Interpreter/gym/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/ge/projects/deep_learning_notes/Proj_Neural_Programmer_Interpreter/gym/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/ge/anaconda3/envs/deep-learning/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.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/ge/anaconda3/envs/deep-learning/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.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/ge/projects/deep_learning_notes/Proj_Neural_Programmer_Interpreter/gym/gym/envs/box2d/__init__.py in <module>()
----> 1 from gym.envs.box2d.lunar_lander import LunarLander
      2 from gym.envs.box2d.lunar_lander import LunarLanderContinuous
      3 from gym.envs.box2d.bipedal_walker import BipedalWalker, BipedalWalkerHardcore
      4 from gym.envs.box2d.car_racing import CarRacing

/home/ge/projects/deep_learning_notes/Proj_Neural_Programmer_Interpreter/gym/gym/envs/box2d/lunar_lander.py in <module>()
      2 import numpy as np
      3 
----> 4 import Box2D
      5 from Box2D.b2 import (edgeShape, circleShape, fixtureDef, polygonShape, revoluteJointDef, contactListener)
      6 

/home/ge/anaconda3/envs/deep-learning/lib/python3.6/site-packages/Box2D/__init__.py in <module>()
     18 # 3. This notice may not be removed or altered from any source distribution.
     19 #
---> 20 from .Box2D import *
     21 __author__ = '$Date$'
     22 __version__ = '2.3.2'

/home/ge/anaconda3/envs/deep-learning/lib/python3.6/site-packages/Box2D/Box2D.py in <module>()
    433     return _Box2D.b2CheckPolygon(shape, additional_checks)
    434 
--> 435 _Box2D.RAND_LIMIT_swigconstant(_Box2D)
    436 RAND_LIMIT = _Box2D.RAND_LIMIT
    437 

AttributeError: module '_Box2D' has no attribute 'RAND_LIMIT_swigconstant'

In [3]:
?gym.make

In [ ]: