ImportError: cannot import 'rendering' from 'gym.envs.classic_control'

Viewed 2035

I'm working with RL agents, and was trying to replicate the finding of the this paper, wherein they make a custom parkour environment based on Gym open AI, however when trying to render this environment I run into.

import numpy as np
import time
import gym
import TeachMyAgent.environments

env = gym.make('parametric-continuous-parkour-v0', agent_body_type='fish', movable_creepers=True)
env.set_environment(input_vector=np.zeros(3), water_level = 0.1)
env.reset()

while True:
    _, _, d, _ = env.step(env.action_space.sample())
    env.render(mode='human')
    time.sleep(0.1)

c:\users\manu dwivedi\teachmyagent\TeachMyAgent\environments\envs\parametric_continuous_parkour.py in render(self, mode, draw_lidars)
    462 
    463     def render(self, mode='human', draw_lidars=True):
--> 464         from gym.envs.classic_control import rendering
    465         if self.viewer is None:
    466             self.viewer = rendering.Viewer(RENDERING_VIEWER_W, RENDERING_VIEWER_H)

ImportError: cannot import name 'rendering' from 'gym.envs.classic_control' (C:\ProgramData\Anaconda3\envs\teachagent\lib\site-packages\gym\envs\classic_control\__init__.py)

  [1]: https://github.com/flowersteam/TeachMyAgent

I thought this might be a problem with this custom environments and how the authors decided to render it, however, when I try just

from gym.envs.classic_control import rendering

I run into the same error, github users here suggested this can be solved by adding rendor_mode='human' when calling gym.make() rendering, but this seems to only goes for their specific case.

2 Answers

It is not just 'adding' you are using a specific positional argument, then it is passed with render_mode parameter. I think if your problem it is about gym module, try to reinstall the whole library (new enviroment and other features) by typing: pip install gym and calling with -> render_mode:

import numpy as np
import time
import gym
import TeachMyAgent.environments

env = gym.make('parametric-continuous-parkour-v0', render_mode='human', agent_body_type='fish', movable_creepers=True)
env.set_environment(input_vector=np.zeros(3), water_level = 0.1)
env.reset()

while True:
    _, _, d, _ = env.step(env.action_space.sample())
    time.sleep(0.1)
Related