openai / gym

A toolkit for developing and comparing reinforcement learning algorithms.
https://www.gymlibrary.dev
Other
34.9k stars 8.61k forks source link

Simulating MUJOCO Environments in openai gym. FatalError: gladLoadGL error #3192

Open vishwascm opened 1 year ago

vishwascm commented 1 year ago

Question

Hi in the following code I am not able to render() due to FatalError: gladLoadGL error.

import gym env = gym.make("HalfCheetah-v4",render_mode="rgbarray") observation, info = env.reset(seed=42) for in range(1000): action = env.action_space.sample() env.render() observation, reward, terminated, truncated, info = env.step(action) if terminated or truncated: observation, info = env.reset() env.close()

Version details: glfw : 2.5.6 gym : 0.26.2 mujoco : 2.2.0 mujoco-py : 2.1.2.14 Ubuntu: 20.04.3

Please help with this issue

pseudo-rnd-thoughts commented 1 year ago

Could you provide more details on the error or is that all it says? This seems like an issue with mujoco or your installation of glfw

vishwascm commented 1 year ago

File ~/miniconda3/envs/v_1/lib/python3.10/site-packages/gym/envs/mujoco/mujoco_rendering.py:57, in RenderContext.init(self, model, data, offscreen) 55 self.vopt = mujoco.MjvOption() 56 self.pert = mujoco.MjvPerturb() ---> 57 self.con = mujoco.MjrContext(self.model, mujoco.mjtFontScale.mjFONTSCALE_150) 59 self._markers = [] 60 self._overlays = {}

FatalError: gladLoadGL error

Hi @pseudo-rnd-thoughts this is the error displayed, please help me through this

vishwascm commented 1 year ago

/home/stoch-lab/miniconda3/envs/v_1/lib/python3.10/site-packages/glfw/init.py:912: GLFWError: (65544) b'X11: The DISPLAY environment variable is missing' warnings.warn(message, GLFWError) /home/stoch-lab/miniconda3/envs/v_1/lib/python3.10/site-packages/glfw/init.py:912: GLFWError: (65537) b'The GLFW library is not initialized' warnings.warn(message, GLFWError)

FatalError Traceback (most recent call last) Cell In[1], line 6 4 for _ in range(100): 5 action = env.action_space.sample() ----> 6 env.render() 7 observation, reward, terminated, truncated, info = env.step(action) 8 print(observation,reward)

File ~/miniconda3/envs/v_1/lib/python3.10/site-packages/gym/core.py:329, in Wrapper.render(self, *args, kwargs) 325 def render( 326 self, *args, *kwargs 327 ) -> Optional[Union[RenderFrame, List[RenderFrame]]]: 328 """Renders the environment.""" --> 329 return self.env.render(args, kwargs)

File ~/miniconda3/envs/v_1/lib/python3.10/site-packages/gym/wrappers/order_enforcing.py:51, in OrderEnforcing.render(self, *args, *kwargs) 46 if not self._disable_render_order_enforcing and not self._has_reset: 47 raise ResetNeeded( 48 "Cannot call env.render() before calling env.reset(), if this is a intended action, " 49 "set disable_render_order_enforcing=True on the OrderEnforcer wrapper." 50 ) ---> 51 return self.env.render(args, **kwargs)

File ~/miniconda3/envs/v_1/lib/python3.10/site-packages/gym/wrappers/env_checker.py:53, in PassiveEnvChecker.render(self, *args, kwargs) 51 if self.checked_render is False: 52 self.checked_render = True ---> 53 return env_render_passive_checker(self.env, *args, *kwargs) 54 else: 55 return self.env.render(args, kwargs)

File ~/miniconda3/envs/v_1/lib/python3.10/site-packages/gym/utils/passive_env_checker.py:316, in env_render_passive_checker(env, *args, *kwargs) 310 else: 311 assert env.render_mode is None or env.render_mode in render_modes, ( 312 "The environment was initialized successfully however with an unsupported render mode. " 313 f"Render mode: {env.render_mode}, modes: {render_modes}" 314 ) --> 316 result = env.render(args, **kwargs) 318 # TODO: Check that the result is correct 320 return result

File ~/miniconda3/envs/v_1/lib/python3.10/site-packages/gym/envs/mujoco/mujoco_env.py:391, in MujocoEnv.render(self) 384 if camera_id is None: 385 camera_id = mujoco.mj_name2id( 386 self.model, 387 mujoco.mjtObj.mjOBJ_CAMERA, 388 camera_name, 389 ) --> 391 self._get_viewer(self.render_mode).render(camera_id=camera_id) 393 if self.render_mode == "rgb_array": 394 data = self._get_viewer(self.render_mode).read_pixels(depth=False)

File ~/miniconda3/envs/v_1/lib/python3.10/site-packages/gym/envs/mujoco/mujoco_env.py:426, in MujocoEnv._get_viewer(self, mode) 423 elif mode in {"rgb_array", "depth_array"}: 424 from gym.envs.mujoco.mujoco_rendering import RenderContextOffscreen --> 426 self.viewer = RenderContextOffscreen(self.model, self.data) 427 else: 428 raise AttributeError( 429 f"Unexpected mode: {mode}, expected modes: {self.metadata['render_modes']}" 430 )

File ~/miniconda3/envs/v_1/lib/python3.10/site-packages/gym/envs/mujoco/mujoco_rendering.py:232, in RenderContextOffscreen.init(self, model, data) 229 self._get_opengl_backend(width, height) 230 self.opengl_context.make_current() --> 232 super().init(model, data, offscreen=True)

File ~/miniconda3/envs/v_1/lib/python3.10/site-packages/gym/envs/mujoco/mujoco_rendering.py:57, in RenderContext.init(self, model, data, offscreen) 55 self.vopt = mujoco.MjvOption() 56 self.pert = mujoco.MjvPerturb() ---> 57 self.con = mujoco.MjrContext(self.model, mujoco.mjtFontScale.mjFONTSCALE_150) 59 self._markers = [] 60 self._overlays = {}

FatalError: gladLoadGL error

pseudo-rnd-thoughts commented 1 year ago

This looks like an issue related to your glfw install. So I don't think could help further