Implementation:Google deepmind Mujoco Python Setup
| Knowledge Sources | |
|---|---|
| Domains | Python Packaging, Build Automation |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Setuptools-based install script that builds and packages the MuJoCo Python bindings, handling CMake compilation and platform-specific shared library bundling.
Description
The setup.py script orchestrates the build of MuJoCo's Python bindings using setuptools with a custom build_ext command. It detects the host platform (Windows, macOS, Linux) to resolve the correct shared library naming patterns (mujoco.dll, libmujoco.*.dylib, libmujoco.so.*) and plugin libraries. The script supports configuration via environment variables (MUJOCO_CMAKE, MUJOCO_CMAKE_ARGS, MUJOCO_PATH, MUJOCO_PLUGIN_PATH) allowing users to point to pre-built MuJoCo installations or customize the CMake invocation. It reads README.md and optional LICENSES_THIRD_PARTY.md to compose the package long description.
Usage
This script is invoked during pip install . or python setup.py build_ext from the python/ directory. It is also called by CI workflows to produce the mujoco Python wheel for distribution.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: python/setup.py
- Lines: 1-379
Key Functions
// Environment variable constants
MUJOCO_CMAKE = 'MUJOCO_CMAKE'
MUJOCO_CMAKE_ARGS = 'MUJOCO_CMAKE_ARGS'
MUJOCO_PATH = 'MUJOCO_PATH'
MUJOCO_PLUGIN_PATH = 'MUJOCO_PLUGIN_PATH'
// Long description assembly
def get_long_description():
current_dir = os.path.dirname('__file__')
with open(os.path.join(current_dir, 'README.md')) as f:
description = f.read()
try:
with open(os.path.join(current_dir, 'LICENSES_THIRD_PARTY.md')) as f:
description = f'{description}\n{f.read()}'
except FileNotFoundError:
pass
return description
// Platform-specific library pattern resolution
def get_mujoco_lib_pattern():
if platform.system() == 'Windows':
return 'mujoco.lib'
elif platform.system() == 'Darwin':
return 'libmujoco.*.dylib'
else:
return 'libmujoco.so.*'
def get_external_lib_patterns():
if platform.system() == 'Windows':
return ['mujoco.dll']
elif platform.system() == 'Darwin':
return ['libmujoco.*.dylib']
else:
return ['libmujoco.so.*']
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
MUJOCO_CMAKE |
Environment variable | No | Path to a custom CMake executable; defaults to system cmake
|
MUJOCO_CMAKE_ARGS |
Environment variable | No | Additional arguments forwarded to the CMake configure step |
MUJOCO_PATH |
Environment variable | No | Path to a pre-built MuJoCo installation (skips CMake build if set) |
MUJOCO_PLUGIN_PATH |
Environment variable | No | Path to pre-built MuJoCo plugin shared libraries |
README.md |
File | Yes | Package description source used for PyPI long description |
LICENSES_THIRD_PARTY.md |
File | No | Optional third-party license text appended to the long description |
Outputs
| Name | Type | Description |
|---|---|---|
mujoco Python package |
Wheel / sdist | Installable Python package containing compiled bindings and bundled shared libraries |
| Platform shared libraries | .so / .dylib / .dll |
MuJoCo native libraries copied into the package for runtime use |
| Plugin shared libraries | .so / .dylib / .dll |
Optional MuJoCo plugin libraries bundled into the package |