Last active
June 7, 2023 13:55
-
-
Save BuildingAtom/3119ac9c595324c8001a7454f23bf8c8 to your computer and use it in GitHub Desktop.
NOTE: Please see @franroldans comment below for a much cleaner solution using free-mujoco-py! [Orig] MuJoCo 2.1 working in Google Colab for OpenAI gym. Just add this as a code block near the top of your notebook to get MuJoCo setup.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Include this at the top of your colab code | |
import os | |
if not os.path.exists('.mujoco_setup_complete'): | |
# Get the prereqs | |
!apt-get -qq update | |
!apt-get -qq install -y libosmesa6-dev libgl1-mesa-glx libglfw3 libgl1-mesa-dev libglew-dev patchelf | |
# Get Mujoco | |
!mkdir ~/.mujoco | |
!wget -q https://mujoco.org/download/mujoco210-linux-x86_64.tar.gz -O mujoco.tar.gz | |
!tar -zxf mujoco.tar.gz -C "$HOME/.mujoco" | |
!rm mujoco.tar.gz | |
# Add it to the actively loaded path and the bashrc path (these only do so much) | |
!echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/.mujoco/mujoco210/bin' >> ~/.bashrc | |
!echo 'export LD_PRELOAD=$LD_PRELOAD:/usr/lib/x86_64-linux-gnu/libGLEW.so' >> ~/.bashrc | |
# THE ANNOYING ONE, FORCE IT INTO LDCONFIG SO WE ACTUALLY GET ACCESS TO IT THIS SESSION | |
!echo "/root/.mujoco/mujoco210/bin" > /etc/ld.so.conf.d/mujoco_ld_lib_path.conf | |
!ldconfig | |
# Install Mujoco-py | |
!pip3 install -U 'mujoco-py<2.2,>=2.1' | |
# run once | |
!touch .mujoco_setup_complete | |
try: | |
if _mujoco_run_once: | |
pass | |
except NameError: | |
_mujoco_run_once = False | |
if not _mujoco_run_once: | |
# Add it to the actively loaded path and the bashrc path (these only do so much) | |
try: | |
os.environ['LD_LIBRARY_PATH']=os.environ['LD_LIBRARY_PATH'] + ':/root/.mujoco/mujoco210/bin' | |
except KeyError: | |
os.environ['LD_LIBRARY_PATH']='/root/.mujoco/mujoco210/bin' | |
try: | |
os.environ['LD_PRELOAD']=os.environ['LD_PRELOAD'] + ':/usr/lib/x86_64-linux-gnu/libGLEW.so' | |
except KeyError: | |
os.environ['LD_PRELOAD']='/usr/lib/x86_64-linux-gnu/libGLEW.so' | |
# presetup so we don't see output on first env initialization | |
import mujoco_py | |
_mujoco_run_once = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
after installing this free version when I am making env=gym.make('Humanoid-v2') and when i write env.render()
I am getting error
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)
in ()
----> 1 env.render()
4 frames
/usr/local/lib/python3.7/dist-packages/mujoco_py/mjviewer.py in init(self, sim)
26
27 def init(self, sim):
---> 28 super().init(sim)
29
30 self._gui_lock = Lock()
mjrendercontext.pyx in mujoco_py.cymj.MjRenderContextWindow.init()
mjrendercontext.pyx in mujoco_py.cymj.MjRenderContext.init()
mjrendercontext.pyx in mujoco_py.cymj.MjRenderContext._setup_opengl_context()
opengl_context.pyx in mujoco_py.cymj.GlfwContext.init()
opengl_context.pyx in mujoco_py.cymj.GlfwContext._init_glfw()
GlfwError: Failed to initialize GLFW
Kindly tell me why i am unable to view