MyoHub/myosuite

Error with SAR tutorial (Could not find module 'EGL')

PlusJHChen opened this issue · 2 comments

When I run the code 'train('myoLegWalk-v0', 'play_period', 1.5e6, '0')' in the step 1.1 in the SAR tutorial, errors occur as below:

Someone solves similar error with EGL by commenting ''os.environ['PYOPENGL_PLATFORM'] = 'egl', but I cannot find that. I only find 'os.environ['MUJOCO_GL'] = 'egl'' in the 'SAR_tutorial_utils.py' but commenting it does not solve the problem. Does any one meet that error or have any solutions? Thanks very much!


FileNotFoundError Traceback (most recent call last)
File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\OpenGL\platform\egl.py:80, in EGLPlatform.EGL(self)
79 try:
---> 80 return ctypesloader.loadLibrary(
81 ctypes.cdll,
82 'EGL',
83 mode=ctypes.RTLD_GLOBAL
84 )
85 except OSError as err:

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\OpenGL\platform\ctypesloader.py:36, in loadLibrary(dllType, name, mode)
35 else:
---> 36 return _loadLibraryWindows(dllType, name, mode)

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\OpenGL\platform\ctypesloader.py:89, in _loadLibraryWindows(dllType, name, mode)
88 try:
---> 89 return dllType( name, mode )
90 except Exception as err:

File D:\Anaconda3\envs\myosuite-sb1.7\lib\ctypes_init_.py:374, in CDLL.init(self, name, mode, handle, use_errno, use_last_error, winmode)
373 if handle is None:
--> 374 self._handle = _dlopen(self._name, mode)
375 else:

FileNotFoundError: ("Could not find module 'EGL' (or one of its dependencies). Try using the full path with constructor syntax.", 'EGL', None)

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last)
Cell In[13], line 1
----> 1 train('myoLegWalk-v0', 'play_period', 1.5e6, '0')

Cell In[6], line 10, in train(env_name, policy_name, timesteps, seed)
1 def train(env_name, policy_name, timesteps, seed):
2 """
3 Trains a policy using sb3 implementation of SAC.
4
(...)
8 seed: str (not int); relevant if you want to train multiple policies with the same params
9 """
---> 10 env = gym.make(env_name)
11 env = Monitor(env)
12 env = DummyVecEnv([lambda: env])

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\gym\envs\registration.py:156, in make(id, **kwargs)
155 def make(id, **kwargs):
--> 156 return registry.make(id, **kwargs)

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\gym\envs\registration.py:101, in EnvRegistry.make(self, path, **kwargs)
99 logger.info('Making new env: %s', path)
100 spec = self.spec(path)
--> 101 env = spec.make(**kwargs)
102 # We used to have people override _reset/_step rather than
103 # reset/step. Set _gym_disable_underscore_compat = True on
104 # your environment if you use these methods and don't want
105 # compatibility code to be invoked.
106 if hasattr(env, "_reset") and hasattr(env, "_step") and not getattr(env, "_gym_disable_underscore_compat", False):

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\gym\envs\registration.py:73, in EnvSpec.make(self, kwargs)
71 else:
72 cls = load(self._entry_point)
---> 73 env = cls(
_kwargs)
75 # Make the enviroment aware of which spec it came from.
76 env.unwrapped.spec = self

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\myosuite\envs\myo\myobase\walk_v0.py:185, in WalkEnvV0.init(self, model_path, obsd_model_path, seed, **kwargs)
178 gym.utils.EzPickle.init(self, model_path, obsd_model_path, seed, **kwargs)
180 # This two step construction is required for pickling to work correctly. All arguments to all init
181 # calls must be pickle friendly. Things like sim / sim_obsd are NOT pickle friendly. Therefore we
182 # first construct the inheritance chain, which is just init calls all the way down, with env_base
183 # creating the sim / sim_obsd instances. Next we run through "setup" which relies on sim / sim_obsd
184 # created in init to complete the setup.
--> 185 super().init(model_path=model_path, obsd_model_path=obsd_model_path, seed=seed, env_credits=self.MYO_CREDIT)
186 self._setup(**kwargs)

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\myosuite\envs\env_base.py:57, in MujocoEnv.init(self, model_path, obsd_model_path, seed, env_credits)
54 self.seed(seed)
56 # sims
---> 57 self.sim = SimScene.get_sim(model_path)
58 self.sim_obsd = SimScene.get_sim(obsd_model_path) if obsd_model_path else self.sim
59 self.sim.forward()

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\myosuite\physics\sim_scene.py:69, in SimScene.get_sim(model_handle)
67 return SimScene.create(model_handle=model_handle, backend=SimBackend.MUJOCO_PY)
68 elif sim_backend == SimBackend.MUJOCO:
---> 69 return SimScene.create(model_handle=model_handle, backend=SimBackend.MUJOCO)
70 else:
71 raise ValueError("Unknown sim_backend: {}. Available choices: MUJOCO_PY, MUJOCO")

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\myosuite\physics\sim_scene.py:56, in SimScene.create(backend, *args, **kwargs)
54 return mjpy_sim_scene.MjPySimScene(*args, **kwargs)
55 elif backend == SimBackend.MUJOCO:
---> 56 from myosuite.physics import mj_sim_scene # type: ignore
57 return mj_sim_scene.DMSimScene(*args, **kwargs)
58 else:

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\myosuite\physics\mj_sim_scene.py:18
16 import_utils.dm_control_isavailable()
17 import_utils.mujoco_isavailable()
---> 18 import dm_control.mujoco as dm_mujoco
20 from myosuite.renderer.mj_renderer import MJRenderer
21 from myosuite.physics.sim_scene import SimScene

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\dm_control\mujoco_init_.py:18
1 # Copyright 2017 The dm_control Authors.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
(...)
13 # limitations under the License.
14 # ============================================================================
16 """Mujoco implementations of base classes."""
---> 18 from dm_control.mujoco.engine import action_spec
20 from dm_control.mujoco.engine import Camera
21 from dm_control.mujoco.engine import MovableCamera

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\dm_control\mujoco\engine.py:41
37 from typing import Callable, NamedTuple, Optional, Union
39 from absl import logging
---> 41 from dm_control import _render
42 from dm_control.mujoco import index
43 from dm_control.mujoco import wrapper

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\dm_control_render_init_.py:86
81 raise RuntimeError(
82 'Environment variable {} must be one of {!r}: got {!r}.'
83 .format(constants.MUJOCO_GL, sorted(all_names), BACKEND))
84 logging.info('MUJOCO_GL=%s, attempting to import specified OpenGL backend.',
85 BACKEND)
---> 86 Renderer = import_func()
87 else:
88 logging.info('MUJOCO_GL is not set, so an OpenGL backend will be chosen '
89 'automatically.')

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\dm_control_render_init_.py:36, in _import_egl()
35 def _import_egl():
---> 36 from dm_control._render.pyopengl.egl_renderer import EGLContext
37 return EGLContext

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\dm_control_render\pyopengl\egl_renderer.py:39
31 raise ImportError(
32 'Cannot use EGL rendering platform. '
33 'The PYOPENGL_PLATFORM environment variable is set to {!r} '
34 '(should be either unset or {!r}).'
35 .format(PYOPENGL_PLATFORM, constants.EGL[0]))
38 # pylint: disable=g-import-not-at-top
---> 39 from dm_control._render.pyopengl import egl_ext as EGL
40 from OpenGL import error
43 def create_initialized_headless_egl_display():

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\dm_control_render\pyopengl\egl_ext.py:19
16 """Extends OpenGL.EGL with definitions necessary for headless rendering."""
18 import ctypes
---> 19 from OpenGL.platform import ctypesloader # pylint: disable=g-bad-import-order
20 try:
21 # Nvidia driver seems to need libOpenGL.so (as opposed to libGL.so)
22 # for multithreading to work properly. We load this in before everything else.
23 ctypesloader.loadLibrary(ctypes.cdll, 'OpenGL', mode=ctypes.RTLD_GLOBAL)

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\OpenGL\platform_init_.py:56
53 plugin.install(globals())
54 return plugin
---> 56 _load()
58 def types(resultType,*argTypes):
59 """Decorator to add returnType, argTypes and argNames to a function"""

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\OpenGL\platform_init_.py:53, in _load()
50 plugin = plugin_class()
52 # install into the platform module's namespace now
---> 53 plugin.install(globals())
54 return plugin

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\OpenGL\platform\baseplatform.py:97, in BasePlatform.install(self, namespace)
95 """Install this platform instance into the platform module"""
96 for name in self.EXPORTED_NAMES:
---> 97 namespace[ name ] = getattr(self,name,None)
98 namespace['PLATFORM'] = self
99 return self

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\OpenGL\platform\baseplatform.py:15, in lazy_property.get(self, obj, cls)
14 def get( self, obj, cls ):
---> 15 value = self.fget( obj )
16 setattr( obj, self.fget.name, value)
17 return value

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\OpenGL\platform\egl.py:106, in EGLPlatform.GetCurrentContext(self)
104 @baseplatform.lazy_property
105 def GetCurrentContext( self ):
--> 106 return self.EGL.eglGetCurrentContext

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\OpenGL\platform\baseplatform.py:15, in lazy_property.get(self, obj, cls)
14 def get( self, obj, cls ):
---> 15 value = self.fget( obj )
16 setattr( obj, self.fget.name, value)
17 return value

File D:\Anaconda3\envs\myosuite-sb1.7\lib\site-packages\OpenGL\platform\egl.py:86, in EGLPlatform.EGL(self)
80 return ctypesloader.loadLibrary(
81 ctypes.cdll,
82 'EGL',
83 mode=ctypes.RTLD_GLOBAL
84 )
85 except OSError as err:
---> 86 raise ImportError("Unable to load EGL library", *err.args)

ImportError: ('Unable to load EGL library', "Could not find module 'EGL' (or one of its dependencies). Try using the full path with constructor syntax.", 'EGL', None)

Hi @PlusJHChen , I am trying to replicate this on Windows with no success. This you have problems with the other tutorials too?

Hi @PlusJHChen , I am trying to replicate this on Windows with no success. This you have problems with the other tutorials too?

Hi, @Vittorio-Caggiano, I have solved this issue and run the SAR tutorial successfully by reinstalling and commenting the above code again. To be honest, I cannot figure out now why the tutorial is run without success previously by commenting the code. But what I can confirm is that commenting the 'os.environ['MUJOCO_GL'] = 'egl'' in the 'SAR_tutorial_utils.py' can really solve the problem of 'Could not find module 'EGL''.