Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mjpython bug when installed with uv package manager #1923

Open
jonzamora opened this issue Aug 25, 2024 · 2 comments
Open

mjpython bug when installed with uv package manager #1923

jonzamora opened this issue Aug 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@jonzamora
Copy link

jonzamora commented Aug 25, 2024

Hi,

When i try to run a MuJoCo script with mjpython on my Macbook after installing mujoco with the uv package manager, I get an error message. To reproduce the error, I ran the following commands:

# Install `uv` on macOS and Linux.
$ curl -LsSf https://astral.sh/uv/install.sh | sh

# Create project and run mjpython
uv init mujoco-example
cd mujoco-example
uv add mujoco
source .venv/bin/activate
mjpython

The error says the following:

(.venv) jonzamora@mbp mujoco-example % mjpython
failed to dlopen path '/Users/jonzamora/Research/mujoco-example/.venv/bin/python': dlopen(/Users/jonzamora/Research/mujoco-example/.venv/bin/python, 0x000A): Library not loaded: @executable_path/../lib/libpython3.10.dylib
  Referenced from: <4C4C44EE-5555-3144-A1A0-28739E256A39> /Users/jonzamora/.local/share/uv/python/cpython-3.10.14-macos-aarch64-none/bin/python3.10
  Reason: tried: '/Users/jonzamora/Research/mujoco-example/.venv/lib/python3.10/site-packages/mujoco/MuJoCo (mjpython).app/Contents/lib/libpython3.10.dylib' (no such file), '/Users/jonzamora/Research/mujoco-example/.venv/bin/../lib/libpython3.10.dylib' (no such file), '/libpython3.10.dylib' (no such file)

Of course, you could run mjpython main.py, where main.py is a passive viewer rendering script like this:

import time

import mujoco
import mujoco.viewer

m = mujoco.MjModel.from_xml_path('/path/to/mjcf.xml')
d = mujoco.MjData(m)

with mujoco.viewer.launch_passive(m, d) as viewer:
  # Close the viewer automatically after 30 wall-seconds.
  start = time.time()
  while viewer.is_running() and time.time() - start < 30:
    step_start = time.time()

    # mj_step can be replaced with code that also evaluates
    # a policy and applies a control signal before stepping the physics.
    mujoco.mj_step(m, d)

    # Example modification of a viewer option: toggle contact points every two seconds.
    with viewer.lock():
      viewer.opt.flags[mujoco.mjtVisFlag.mjVIS_CONTACTPOINT] = int(d.time % 2)

    # Pick up changes to the physics state, apply perturbations, update options from GUI.
    viewer.sync()

    # Rudimentary time keeping, will drift relative to wall clock.
    time_until_next_step = m.opt.timestep - (time.time() - step_start)
    if time_until_next_step > 0:
      time.sleep(time_until_next_step)

Any help will be greatly appreciated, i'm sure others are also hoping to use a combination of mujoco and uv on their Macbook machines. Thanks!

My Setup

  • Operating system + Machine
    • macOS Sonoma, M3 Max Macbook Pro
  • MuJoCo version (and if the bug is new, the version where it used to work)
    • MuJoCo 3.2.2
  • For Python issues, what bindings are you using (i.e mujoco, dm_control, mujoco-py)?
    • mujoco
@jonzamora jonzamora added the bug Something isn't working label Aug 25, 2024
@jonzamora
Copy link
Author

For comparison, if i create a mamba / conda environment and pip install mujoco, then run mjpython, the expected behavior occurs:

(mujoco) jonzamora@mbp mujoco-example % mjpython
Python 3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:51:49) [Clang 16.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.

@saran-t
Copy link
Member

saran-t commented Oct 18, 2024

I'm not familiar with uv but it seems that for whatever reason this section of code isn't working properly.

Would you be able to run get_executable_path() from mjpython.py from your non-working venv and tell me what you get?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@saran-t @jonzamora and others