google-deepmind / dm_control

Google DeepMind's software stack for physics-based simulation and Reinforcement Learning environments, using MuJoCo.
Apache License 2.0
3.72k stars 660 forks source link

viewer not working on mac osx #276

Open enajx opened 2 years ago

enajx commented 2 years ago

Using the latest install for both dm_control and mujoco via pypi, the viewer can not render a window on OSX (intel chip).

Script:

from dm_control import suite
from dm_control import viewer
import numpy as np

env = suite.load(domain_name="point_mass", task_name="easy")
action_spec = env.action_spec()

# Define a uniform random policy.
def random_policy(time_step):
  del time_step  # Unused.
  return np.random.uniform(low=action_spec.minimum,
                           high=action_spec.maximum,
                           size=action_spec.shape)

# Launch the viewer application.
viewer.launch(env, policy=random_policy)

Error output:

script_render_dm.py 51 <module>
"/Users/user/mjc/script_render_dm.py", line 51
viewer.launch(env, policy=random_policy)

__init__.py 39 launch
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/dm_control/viewer/__init__.py", line 39
app = application.Application(title=title, width=width, height=height)

application.py 187 __init__
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/dm_control/viewer/application.py", line 187
self._window = gui.RenderWindow(width, height, title)

__init__.py 34 ErrorRenderWindow
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/dm_control/viewer/gui/__init__.py", line 34
raise ImportError(

ImportError:
Cannot create a window because no windowing system could be imported
gizemozd commented 2 years ago

If your macOS version is Big Sur, this issue might be related to the location of OpenGL libraries.

In my case, the following solved my issue.

Change the following line in ctypesloader.py: fullName = util.find_library( name ) with: fullName = "/System/Library/Frameworks/{}.framework/{}".format(name,name)

NOTE: ctypesloader.py is under ~/<virtual-env>/lib/python3.9/site-packages/OpenGL/platform/ctypesloader.py or something similar.

Source

enajx commented 2 years ago

It's Monterey which seems to have a different folder structures in /System/Library/Frameworks/OpenGL.framework

If linking to the homebrew installed OpenGL with fullName='/usr/local/Cellar/glew/2.2.0_1/lib/libGLEW.2.2.0.dylib' we then get a differnt error:


__init__.py 19 <module>
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/dm_control/viewer/__init__.py", line 19
from dm_control.viewer import application

application.py 20 <module>
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/dm_control/viewer/application.py", line 20
from dm_control.viewer import gui

__init__.py 25 <module>
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/dm_control/viewer/gui/__init__.py", line 25
from dm_control.viewer.gui import glfw_gui

glfw_gui.py 22 <module>
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/dm_control/viewer/gui/glfw_gui.py", line 22
from dm_control.viewer.gui import fullscreen_quad

fullscreen_quad.py 20 <module>
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/dm_control/viewer/gui/fullscreen_quad.py", line 20
from OpenGL import GL

__init__.py 4 <module>
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/OpenGL/GL/__init__.py", line 4
from OpenGL.GL.VERSION.GL_1_1 import *

GL_1_1.py 14 <module>
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/OpenGL/GL/VERSION/GL_1_1.py", line 14
from OpenGL.raw.GL.VERSION.GL_1_1 import *

GL_1_1.py 7 <module>
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/OpenGL/raw/GL/VERSION/GL_1_1.py", line 7
from OpenGL.raw.GL import _errors

_errors.py 4 <module>
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/OpenGL/raw/GL/_errors.py", line 4
_error_checker = _ErrorChecker( _p, _p.GL.glGetError )

error.py 183 __init__
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/OpenGL/error.py", line 183
self._isValid = platform.CurrentContextIsValid

baseplatform.py 15 __get__
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/OpenGL/platform/baseplatform.py", line 15
value = self.fget( obj )

baseplatform.py 356 CurrentContextIsValid
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/OpenGL/platform/baseplatform.py", line 356
return self.GetCurrentContext

baseplatform.py 15 __get__
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/OpenGL/platform/baseplatform.py", line 15
value = self.fget( obj )

darwin.py 62 GetCurrentContext
"/Users/user/.virtualenvs/p39/lib/python3.9/site-packages/OpenGL/platform/darwin.py", line 62
return self.CGL.CGLGetCurrentContext

__init__.py 387 __getattr__
"/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 387
func = self.__getitem__(name)

__init__.py 392 __getitem__
"/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 392
func = self._FuncPtr((name_or_ordinal, self))

AttributeError:
dlsym(0x214e746e0, CGLGetCurrentContext): symbol not found
saran-t commented 2 years ago

Since the original post is from last week, I presume you're still working with mujoco version 2.1.3?

If that's the case could you please try upgrading to 2.1.4 to see if the issue persists? (In particular, libGLEW is no longer required).

enajx commented 2 years ago

I just upgraded to 2.1.4, same issue sadly persists