Арсен Гумин
Арсен Гумин

Reputation: 15

Python-gym. Does not see the environment

Please tell me what might be the problem?
Only one environment starts correctly. (Trolley)

import gym
env = gym.make('CarRacing-v0')
env.reset()
for _ in range(1000):
    env.render()
    env.step(env.action_space.sample())

AttributeError Traceback (most recent call last) in () 1 import gym ----> 2 env = gym.make('CarRacing-v0') 3 env.reset() 4 for _ in range(1000): 5 env.render()

C:\Anaconda3\lib\site-packages\gym-0.15.6-py3.6.egg\gym\envs\registration.py in make(id, **kwargs) 140 141 def make(id, **kwargs): --> 142 return registry.make(id, **kwargs) 143 144 def spec(id):

C:\Anaconda3\lib\site-packages\gym-0.15.6-py3.6.egg\gym\envs\registration.py in make(self, path, **kwargs) 85 logger.info('Making new env: %s', path) 86 spec = self.spec(path) ---> 87 env = spec.make(**kwargs) 88 # We used to have people override _reset/_step rather than 89 # reset/step. Set _gym_disable_underscore_compat = True on

C:\Anaconda3\lib\site-packages\gym-0.15.6-py3.6.egg\gym\envs\registration.py in make(self, kwargs) 56 env = self.entry_point(_kwargs) 57 else: ---> 58 cls = load(self.entry_point) 59 env = cls(**_kwargs) 60

C:\Anaconda3\lib\site-packages\gym-0.15.6-py3.6.egg\gym\envs\registration.py in load(name) 16 mod_name, attr_name = name.split(":") 17 mod = importlib.import_module(mod_name) ---> 18 fn = getattr(mod, attr_name) 19 return fn 20

AttributeError: module 'gym.envs.box2d' has no attribute 'CarRacing'

Upvotes: 0

Views: 1162

Answers (1)

Andi Schroff
Andi Schroff

Reputation: 1334

I am not using anaconda but virtualenv. Nevertheless, I had initially the same error. It seems that the "Classical" Environments were working but not the Box2D games. I tried to install Box2D separately with "pip install Box2D" but I received errors for a missing swig.exe when installing dependency "wheel".

To solve this,

  • I downloaded swig and then added the path to the swig.exe to my windows path.
  • Then I uninstalled gym and Box2D.
  • Then I installed gym and then Box2D with "pip install gym[box2d]"

enter image description here

Upvotes: 1

Related Questions