Skip to content

Fix mjpython libpython resolution for uv and @rpath interpreters#3355

Open
Mika412 wants to merge 3 commits into
google-deepmind:mainfrom
Mika412:fix-mjpython-libpython-venv-rpath
Open

Fix mjpython libpython resolution for uv and @rpath interpreters#3355
Mika412 wants to merge 3 commits into
google-deepmind:mainfrom
Mika412:fix-mjpython-libpython-venv-rpath

Conversation

@Mika412

@Mika412 Mika412 commented Jun 21, 2026

Copy link
Copy Markdown

On macOS, running anything under mjpython on a uv managed Python fails with dyld: Library not loaded: @rpath/libpython3.x.dylib. The same failure occurs with any interpreter that links libpython through @rpath.

At startup, mjpython.py parses otool -l and adds the interpreter's library directories to DYLD_FALLBACK_LIBRARY_PATH so libpython resolves. Two bugs broke that for @rpath interpreters:

  • It ran dirname() on every entry, but LC_RPATH values are already directories, so the real lib/ got reduced to its parent and libpython was never found.
  • It didn't follow the interpreter symlink first, so for a venv (bin/python points at the base interpreter) the paths were anchored in the wrong place.

Also swaps the main-thread startup busy-wait (while (!py_initialized.load()) {}) for a dispatch semaphore, and makes the three interpreter-bootstrap calls fail loudly instead of silently continuing into a broken state.

All changes are limited to the macOS-only mjpython launcher (python/mujoco/mjpython/). Nothing else is affected.

This fixes the failure reported in #1923 (closed without a fix) and astral-sh/uv#8953.

@kevinzakka kevinzakka requested a review from saran-t June 22, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant