openai / mujoco-py

MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3.
Other
2.81k stars 810 forks source link

RuntimeError: Failed to initialize OpenGL #714

Closed zichunxx closed 2 years ago

zichunxx commented 2 years ago

I know this type of problem has been asked many times, and I have tried to follow these methods (#665, #187) to solve my problem, but it seems useless.

Here is my test code:

import mujoco_py

MODEL_XML = """
<?xml version="1.0" ?>
<mujoco>
    <worldbody>
    <camera name="cam0" pos="-0.1 0.1 0.0" quat="0.707 0.707 0 0" />
        <body name="box" pos="0 0 0.2">
            <geom size="0.15 0.15 0.15" type="box"/>
            <joint axis="1 0 0" name="box:x" type="slide"/>
            <joint axis="0 1 0" name="box:y" type="slide"/>
        </body>
        <body name="floor" pos="0 0 0.025">
            <geom size="1.0 1.0 0.02" rgba="0 1 0 1" type="box"/>
        </body>
    </worldbody>
</mujoco>
"""
model = mujoco_py.load_model_from_xml(MODEL_XML)
sim = mujoco_py.MjSim(model)
viewer = mujoco_py.MjViewer(sim)
image = sim.render(width=300, height = 300, camera_name='cam0', depth=False)
print(image)

Then I met the following error:

File "mujoco_py/mjsim.pyx", line 156, in mujoco_py.cymj.MjSim.render
File "mujoco_py/mjsim.pyx", line 158, in mujoco_py.cymj.MjSim.render
File "mujoco_py/mjrendercontext.pyx", line 45, in mujoco_py.cymj.MjRenderContext.__init__
File "mujoco_py/mjrendercontext.pyx", line 113, in mujoco_py.cymj.MjRenderContext._setup_opengl_context
File "mujoco_py/opengl_context.pyx", line 130, in mujoco_py.cymj.OffscreenOpenGLContext.__init__
RuntimeError: Failed to initialize OpenGL

By browsing through some issues, the following code is the reason for this error.

image = sim.render(width='300', height = '300', camera_name='cam0', depth=False)

If I replace this line with viewer.render(), the glfw window will show up. However, this is not the result that I want and the image is not avaliable.

The operating system and mujoco_py which I used are

Linux system: Ubuntu 18.04.
Mujoco_py version: 2.0.2.5.

It seems that unset LD_PRELOAD is useless for me. When I try this method, the window gets stuck and the following error appears

ERROR: GLEW initialization error: Missing GL version

I also have no libGL.so in /usr/lib/nvidia-510, but I'm not sure if this file does have an impact on this issue.

Has anyone successfully solved this problem? I would appreciate a response! Thx!

DDCoan commented 2 years ago

Hi, how did you solve this issue? Could you pls maybe share your solution? many thanks!

zichunxx commented 2 years ago

Hi, how did you solve this issue? Could you pls maybe share your solution? many thanks!

Hi, I'm sorry for replying now. I can't remember the exact details, but I can list all the methods I've tried below.

(1) https://github.com/openai/mujoco-py/issues/187#issue-292316408

(2) Check the device_id in the programming. Some related issues can be found.

(3) The following two lines of code conflict with each other and cannot be implemented at the same time, which is a bug of Mujoco.

viewer = mujoco_py.MjViewer(sim)
image = sim.render(width=300, height = 300, camera_name='cam0', depth=False)

Hope these are helpful to you!

DDCoan commented 2 years ago

many thanks!

Irismoon commented 2 years ago

many thanks!

Hi, have you addressed the issue?

Thanks!

DDCoan commented 2 years ago

unset LD_PRELOAD worked for me. did you try that?

Dimoo-POP commented 2 years ago

unset LD_PRELOAD worked for me. did you try that?

Hi! Should this command (unset LD_PRELOAD) be entered in the terminal, before starting the IDE?

DDCoan commented 2 years ago

you can enter unset LD_PRELOAD in terminal then "python yourfile.py to run your code

Dimoo-POP commented 2 years ago

you can enter unset LD_PRELOAD in terminal then "python yourfile.py to run your code

Thank you!

Irismoon commented 2 years ago

unset LD_PRELOAD worked for me. did you try that?

Yes, I tried that. But that did not help with the error. And finally this problem is addressed by using GPU in my case.

irfanrah commented 2 years ago

unset LD_PRELOAD worked for me. did you try that?

Hi, I tried this and got this error

Creating window glfw ERROR: GLEW initalization error: Missing GL version Press Enter to exit