Created
July 1, 2025 19:44
-
-
Save Tolga-dev/082b4f353b325540cf9e726c4b449e90 to your computer and use it in GitHub Desktop.
setting up mujoco test.ipynb
Author
Author
!/content/py38env/bin/python main.py
from IPython.display import Image
Image(filename="juggler.gif")
you might ask what is inside of main.py? dont worry i added as text comment.
I added here also
#!/usr/bin/env python3
from mujoco_py import load_model_from_path, MjSim, MjRenderContextOffscreen
import matplotlib.pyplot as plt
from PIL import Image
import os
# xml_path = "/content/model_source.xml"
# with open(xml_path, "w") as f:
# f.write(MODEL_XML)
model = load_model_from_path("/content/mujoco-py/xmls/tosser.xml")
sim = MjSim(model)
# Create the offscreen rendering context and attach it
render_context = MjRenderContextOffscreen(sim)
sim.add_render_context(render_context)
from PIL import Image
frames = []
for i in range(100):
print(i)
sim.step()
frame = sim.render(width=512, height=512)
frames.append(Image.fromarray(frame))
frames[0].save("juggler.gif", save_all=True, append_images=frames[1:], duration=40, loop=0)
Author
General code is short and not following best standards.
Author
Revisions will be made on code. Current second version is correctly working as I expected.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried to solve the mujoco-py compatibility issue. Since mujoco-py is deprecated and only supports Python 3.8, it doesn't work directly on Colab (which uses Python 3.11 by default). However, you can work around this by creating a custom Python environment with version 3.8, and you have to change Cython>=0.27.2,<3 from requirements.txt
I followed this approach and was able to get it running. I've included the results below. Hope this helps!