Hi,
I am trying to use the MjViewer on a remote instance. Get the following traceback on initializing the MjViewer. (This is even if I use the -X server while doing the ssh). Any pointers on how to use headless rendering with MjViewer?
````
GLFW error (code %d): %s 65544 b'X11: The DISPLAY environment variable is missing
GLFW error (code %d): %s 65544 b'X11: The DISPLAY environment variable is missing
GlfwError Traceback (most recent call last)
----> 1 viewer = MjViewer(sim)
/usr/local/lib/python3.5/dist-packages/mujoco_py/mjviewer.py in __init__(self, sim)
131
132 def __init__(self, sim):
--> 133 super().__init__(sim)
134
135 self._ncam = sim.model.ncam
/usr/local/lib/python3.5/dist-packages/mujoco_py/mjviewer.py in __init__(self, sim)
24
25 def __init__(self, sim):
---> 26 super().__init__(sim)
27
28 self._gui_lock = Lock()
/usr/local/lib/python3.5/dist-packages/mujoco_py/mjrendercontext.pyx in mujoco_py.cymj.MjRenderContextWindow.__init__()
/usr/local/lib/python3.5/dist-packages/mujoco_py/mjrendercontext.pyx in mujoco_py.cymj.MjRenderContext.__init__()
/usr/local/lib/python3.5/dist-packages/mujoco_py/mjrendercontext.pyx in mujoco_py.cymj.MjRenderContext._setup_opengl_context()
/usr/local/lib/python3.5/dist-packages/mujoco_py/opengl_context.pyx in mujoco_py.cymj.GlfwContext.__init__()
/usr/local/lib/python3.5/dist-packages/mujoco_py/opengl_context.pyx in mujoco_py.cymj.GlfwContext._init_glfw()
GlfwError: Failed to initialize GLFW
````
On using the Dockerfile with the Xdummy entry point, I get this:
viewer = MjViewer(sim)
GLFW error (code %d): %s 65544 b'X11: RandR gamma ramp support seems broken'
GLFW error (code %d): %s 65544 b'Linux: Failed to watch for joystick connections in /dev/input: No such file or directory'
GLFW error (code %d): %s 65544 b'Linux: Failed to open joystick device directory /dev/input: No such file or directory'
libEGL warning: DRI2: failed to authenticate
Creating window glfw
Guess it does create the glfw window now... Is this the right way?
@aravind0706 Hi, did you fix this problem?
@aravind0706 Also having this issue.
Same issue here
I fixed this by using the latest bindings. You can call sim.render() with desired image size and mujoco_py will initialize a an offscreen render context. sim.render() will return image data as an np array that can be converted to an img with the likes of PIL. Doesn't fix the animation issue directly however.
@BTickell would mind describing the process in a bit more detail. What did you actually do differently if you could possibly outline the steps that would be great.
@kirk86 Instead of creating a new viewer with MjViewer(sim), call sim.render(width, height) which will return an np array of image data. Subsequent calls to render should use the context which you can find in sim.render_contexts I believe.
@BTickell thank you for your answers. I believe that a minimal working example would be ideal and helpful to a lot of people landing in this issue. For instance let's take the mujoco_py/examples/body_interaction.py as a concrete example.
In the last couple of lines that file looks like:
model = load_model_from_xml(MODEL_XML)
sim = MjSim(model)
viewer = MjViewer(sim)
I've changed viewer = MjViewer(sim) as per your suggestion viewer = sim.render(600, 600) but I still get an error. Additionally I added in the end sim.render_contexts(viewer) but still I get an error. What am I doing wrong here?
Thanks!
Ok sim.render(...) creates an offscreen render_context but returns the image data. So if you want to get images do
model = load_model_from_xml(MODEL_XML)
sim = MjSim(model)
img = sim.render(600, 600)
img will have a [600, 600] np array with image data that you can now use. There will be an offscreen render context inside of sim.render_contexts but this is an array and you shouldn't need this to grab images. Just make additional calls to render(...). So for a basic example, once you have sim and model set up.
imgs = []
for i in range(20):
sim.step()
imgs.append(sim.render(600, 600))
Should give you image data for those 20 steps.
This is a bug of glfw3.2. Try installing glfw 3.3+.
Run
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so
xvfb-run -a -s "-screen 0 1400x900x24" bash
Or just paste them in your .bashsrc.
Everyone who begins to use the python bindings for mjp runs into this exact issue. 馃槃 It should almost be in the installation notes at this point.
Most helpful comment
Run
Or just paste them in your
.bashsrc.