Skip to content

Instantly share code, notes, and snippets.

@Tolga-dev
Created July 1, 2025 19:44
Show Gist options
  • Select an option

  • Save Tolga-dev/082b4f353b325540cf9e726c4b449e90 to your computer and use it in GitHub Desktop.

Select an option

Save Tolga-dev/082b4f353b325540cf9e726c4b449e90 to your computer and use it in GitHub Desktop.
setting up mujoco test.ipynb
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Tolga-dev
Copy link
Author

Tolga-dev commented Jul 1, 2025

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!

juggler

@Tolga-dev
Copy link
Author

Tolga-dev commented Jul 1, 2025

!/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)

@Tolga-dev
Copy link
Author

General code is short and not following best standards.

@Tolga-dev
Copy link
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