Gym: Custom Environments Attribute Error

Created on 3 Feb 2018  路  7Comments  路  Source: openai/gym

I wrote an environment called SimpleEnv that works on the machine I made it on (a couple of weeks ago). I copied the code for this environment onto another machine, installed both it and gym via pip, and I receive this error.

WARN: Environment '<class 'gym_simple.envs.env.SimpleEnv'>' has deprecated methods. Compatibility code invoked.
Traceback (most recent call last):
  File "simple_test.py", line 54, in <module>
    tf.app.run(main)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 124, in run
    _sys.exit(main(argv))
  File "simple_test.py", line 41, in main
    env = gym.make('gym-simple-v0')
  File "/usr/local/lib/python3.5/dist-packages/gym/envs/registration.py", line 163, in make
    return registry.make(id)
  File "/usr/local/lib/python3.5/dist-packages/gym/envs/registration.py", line 121, in make
    patch_deprecated_methods(env)
  File "/usr/local/lib/python3.5/dist-packages/gym/envs/registration.py", line 181, in patch_deprecated_methods
    env.seed  = env._seed
AttributeError: 'SimpleEnv' object has no attribute '_seed'

There was an update to the Github repository between the times of me writing the code and this error occurring. I am unaware if an update was done to the pip gym package in that time, but this seems to be the issue, as the SimpleEnv environment still works on the initial machine (same code)

Most helpful comment

@JohnYiQC Hi! I simply changed the methods to no longer have the underscore. So鈥攁ssuming you are reading the documentation here鈥攜ou would do the exact same thing, except your gym-foo/gym_foo/envs/foo_env.py file will now be of the form:

import gym
from gym import error, spaces, utils
from gym.utils import seeding

class FooEnv(gym.Env):
  metadata = {'render.modes': ['human']}

  def __init__(self):
    ...
  def step(self, action):
    ...
  def reset(self):
    ...
  def render(self, mode='human', close=False):
    ...

All 7 comments

The new version of gym (0.9.6) assumes that all deprecated envs (that implement the _method() interface instead of the new method() interface), implement a method called _seed(). You can implement a wrapper to your old seed method as _seed() and it should fix the issue.

@thevazking, thank you for the assistance; this worked!

@mvarble , Hi, I'm fairly new to python much less to machine learning, but I encountered exactly the same problem as what you've reported. How exactly did you solve the problem? Can you please post a snippet of your code like how you implemented the wrapper?
Thanks!

@JohnYiQC Hi! I simply changed the methods to no longer have the underscore. So鈥攁ssuming you are reading the documentation here鈥攜ou would do the exact same thing, except your gym-foo/gym_foo/envs/foo_env.py file will now be of the form:

import gym
from gym import error, spaces, utils
from gym.utils import seeding

class FooEnv(gym.Env):
  metadata = {'render.modes': ['human']}

  def __init__(self):
    ...
  def step(self, action):
    ...
  def reset(self):
    ...
  def render(self, mode='human', close=False):
    ...

@mvarble Thanks! That got me going on!

@mvarble and @thevazking : thanks a lot ... :)

I'm sorry, but can someone spell this out for me? I've tried removing the underscore at the front of each method and I still receive the same error when I try to run an env, in this case from https://github.com/xinleipan/gym-gridworld

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tylerlekang picture tylerlekang  路  3Comments

RuofanKong picture RuofanKong  路  4Comments

david8373 picture david8373  路  4Comments

Spiral-Galaxy picture Spiral-Galaxy  路  3Comments

pickittwice picture pickittwice  路  4Comments