Explain how to build Python and C/C++ sources from the same codebase.

The previous instructions use a pre-built binary from MuJoCo and do not cover
the use-case of building C/C++ and Python bindings from the same codebase.

PiperOrigin-RevId: 802060401
Change-Id: I6d0b9c7c2269ff596ac706b716ff6c95b42c5d99
This commit is contained in:
Michiel Blokzijl
2025-09-02 02:50:40 -07:00
committed by Copybara-Service
parent 8acd83f317
commit ee777f74d3
2 changed files with 26 additions and 14 deletions
+2
View File
@@ -111,6 +111,8 @@ target directory.
5. Select the directory: :shell:`cmake $PATH_TO_CLONED_REPO -DCMAKE_INSTALL_PREFIX=<my_install_dir>` 5. Select the directory: :shell:`cmake $PATH_TO_CLONED_REPO -DCMAKE_INSTALL_PREFIX=<my_install_dir>`
#. After building, install with ``cmake --install .`` #. After building, install with ``cmake --install .``
#. If desired, proceed to building the Python bindings - see
:ref:`PyBuild`.
**Notes:** **Notes:**
+24 -14
View File
@@ -704,26 +704,33 @@ Building from source
1. Make sure you have CMake and a C++17 compiler installed. 1. Make sure you have CMake and a C++17 compiler installed.
2. Download the `latest binary release <https://github.com/google-deepmind/mujoco/releases>`__ 2. Clone the entire ``mujoco`` repository from GitHub.
from GitHub. On macOS, the download corresponds to a DMG file which you can mount by
double-clicking or running ``hdiutil attach <dmg_file>``. .. code-block:: shell
3. Clone the entire ``mujoco`` repository from GitHub and ``cd`` into the python git clone https://github.com/google-deepmind/mujoco.git
directory:
3. Install MuJoCo. Either download the
`latest binary release <https://github.com/google-deepmind/mujoco/releases>`__
from GitHub (On macOS, the download corresponds to a DMG file which you can
mount by double-clicking or running ``hdiutil attach <dmg_file>``),
or *build* and *install* it from source as per the instructions in
:ref:`inBuild`.
4. ``cd`` into the python directory of the cloned MuJoCo codebase:
.. code-block:: shell .. code-block:: shell
git clone https://github.com/google-deepmind/mujoco.git
cd mujoco/python cd mujoco/python
4. Create a virtual environment: 5. Create a virtual environment:
.. code-block:: shell .. code-block:: shell
python3 -m venv /tmp/mujoco python3 -m venv /tmp/mujoco
source /tmp/mujoco/bin/activate source /tmp/mujoco/bin/activate
5. Generate a `source distribution <https://packaging.python.org/en/latest/glossary/#term-Source-Distribution-or-sdist>`__ 6. Generate a `source distribution <https://packaging.python.org/en/latest/glossary/#term-Source-Distribution-or-sdist>`__
tarball with the ``make_sdist.sh`` script. tarball with the ``make_sdist.sh`` script.
.. code-block:: shell .. code-block:: shell
@@ -736,10 +743,13 @@ Building from source
completion, the script will create a ``dist`` directory with a completion, the script will create a ``dist`` directory with a
``mujoco-x.y.z.tar.gz`` file (where ``x.y.z`` is the version number). ``mujoco-x.y.z.tar.gz`` file (where ``x.y.z`` is the version number).
6. Use the generated source distribution to build and install the bindings. 7. Use the generated source distribution to build and install the bindings.
You'll need to specify the path to the MuJoCo library you downloaded earlier You'll need to specify the path to the MuJoCo library you downloaded
in the ``MUJOCO_PATH`` environment variable, and the path to the MuJoCo or built and installed earlier in the ``MUJOCO_PATH`` environment
plugin directory in the ``MUJOCO_PLUGIN_PATH`` environment variable. variable, and the path to the MuJoCo plugin directory in the
``MUJOCO_PLUGIN_PATH`` environment variable. You can point the
``MUJOCO_PLUGIN_PATH`` environment variable to the ``plugin``
folder of the MuJoCo codebase you cloned.
.. note:: .. note::
For macOS, the files need to be extracted from the DMG. For macOS, the files need to be extracted from the DMG.
@@ -752,7 +762,7 @@ Building from source
cd dist cd dist
MUJOCO_PATH=/PATH/TO/MUJOCO \ MUJOCO_PATH=/PATH/TO/MUJOCO \
MUJOCO_PLUGIN_PATH=/PATH/TO/MUJOCO_PLUGIN \ MUJOCO_PLUGIN_PATH=/PATH/TO/MUJOCO/PLUGIN \
pip install mujoco-x.y.z.tar.gz pip install mujoco-x.y.z.tar.gz
The Python bindings should now be installed! To check that they've been The Python bindings should now be installed! To check that they've been