Skip to content

Commit 84fc2fa

Browse files
committed
Change MuJoCo lookup paths to work with version 2.1.1.
PiperOrigin-RevId: 416848645 Change-Id: I5e7c7ea60559d5afb40a94d71b59390b8c5760a2
1 parent eb2b38e commit 84fc2fa

3 files changed

Lines changed: 52 additions & 32 deletions

File tree

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,35 @@ versions:
5757
* 3.9
5858

5959
Various people have been successful in getting `dm_control` to work on other
60-
Linux distros, OS X, and Windows. We do not provide active support for these,
60+
Linux distros, macOS, and Windows. We do not provide active support for these,
6161
but will endeavour to answer questions on a best-effort basis.
6262

6363
Follow these steps to install `dm_control`:
6464

65-
1. Download MuJoCo 2.1.0 from the Download page on the [MuJoCo website]. MuJoCo
66-
must be installed before `dm_control`, since `dm_control`'s install script
67-
generates Python [`ctypes`] bindings based on MuJoCo's header files. By
68-
default, `dm_control` assumes that the MuJoCo archive is extracted into
69-
`~/.mujoco`.
65+
1. Download MuJoCo 2.1.1 from the
66+
[Releases page on the MuJoCo GitHub repository]. MuJoCo must be installed
67+
before `dm_control`, since `dm_control`'s install script generates Python
68+
[`ctypes`] bindings based on MuJoCo's header files. By default, `dm_control`
69+
assumes that MuJoCo is installed via the following instructions:
70+
71+
- On Linux, extract the tarball into `~/.mujoco`.
72+
- On Windows, extract the zip archive into either `%HOMEPATH%\MuJoCo` or
73+
`%PUBLIC%\MuJoCo`.
74+
- On macOS, either place `MuJoCo.app` into `/Applications`, or place
75+
`MuJoCo.Framework` into `~/.mujoco`.
7076

7177
2. Install the `dm_control` Python package by running `pip install dm_control`.
7278
We recommend `pip install`ing into a `virtualenv`, or with the `--user` flag
7379
to avoid interfering with system packages. At installation time,
74-
`dm_control` looks for the MuJoCo headers from Step 1 in
75-
`~/.mujoco/mujoco210/include`, however this path can be configured with the
76-
`headers-dir` command line argument.
80+
`dm_control` looks for the MuJoCo headers at the paths described in Step 1
81+
by default, however this path can be configured with the `headers-dir`
82+
command line argument.
7783

78-
3. If the shared library provided by MuJoCo (e.g. `libmujoco210.so` or
79-
`libmujoco210.dylib`) is installed at a non-default path, specify its
80-
location using the `MJLIB_PATH` environment variable. This environment
81-
variable should be set to the full path to the library file itself, e.g.
82-
`export MJLIB_PATH=/path/to/libmujoco210.so`.
84+
3. If the shared library provided by MuJoCo (i.e. `libmujoco.so.2.1.1` or
85+
`libmujoco.2.1.1.dylib` or `mujoco.dll`) is installed at a non-default path,
86+
specify its location using the `MJLIB_PATH` environment variable. This
87+
environment variable should be set to the full path to the library file
88+
itself, e.g. `export MJLIB_PATH=/path/to/libmujoco.so.2.1.1`.
8389

8490
## Versioning
8591

@@ -133,6 +139,7 @@ setting the environment variable `EGL_DEVICE_ID=` to the target GPU ID.
133139
`export DYLD_LIBRARY_PATH=$(brew --prefix)/lib:$DYLD_LIBRARY_PATH`.
134140

135141
[EXT_platform_device]: https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_platform_device.txt
142+
[Releases page on the MuJoCo GitHub repository]: https://github.com/deepmind/mujoco/releases
136143
[MuJoCo website]: https://mujoco.org/
137144
[tech report]: https://arxiv.org/abs/2006.12983
138145
[`ctypes`]: https://docs.python.org/3/library/ctypes.html

dm_control/mujoco/wrapper/util.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@
2727
from dm_control.utils import io as resources
2828

2929
_PLATFORM = platform.system()
30-
try:
31-
_PLATFORM_SUFFIX = {
32-
"Linux": "linux",
33-
"Darwin": "macos",
34-
"Windows": "win64"
35-
}[_PLATFORM]
36-
except KeyError:
37-
raise OSError("Unsupported platform: {}".format(_PLATFORM))
3830

3931
# Environment variable that can be used to override the default path to the
4032
# MuJoCo shared library.
@@ -58,15 +50,19 @@ def _get_shared_library_filename():
5850
def _get_default_library_paths(): # pylint: disable=missing-function-docstring
5951
candidate_paths = []
6052
if _PLATFORM == "Linux":
53+
candidate_paths.append(os.path.expanduser("~/.mujoco/mujoco-2.1.1/lib"))
6154
candidate_paths.append(os.path.expanduser("~/.mujoco/lib"))
6255
elif _PLATFORM == "Darwin":
6356
framework_path = "MuJoCo.Framework/Versions/A"
6457
candidate_paths.append(
6558
os.path.join(os.path.expanduser("~/.mujoco"), framework_path))
6659
candidate_paths.append(
67-
os.path.join("/Applications/MuJoCo.App/Frameworks", framework_path))
60+
os.path.join(
61+
"/Applications/MuJoCo.App/Contents/Frameworks", framework_path))
6862
elif _PLATFORM == "Windows":
69-
candidate_paths.append(os.path.expanduser("~/.mujoco/bin"))
63+
candidate_paths.append(os.path.join(
64+
os.environ["HOMEDRIVE"], os.environ["HOMEPATH"], "MuJoCo\\bin"))
65+
candidate_paths.append(os.path.join(os.environ["PUBLIC"], "MuJoCo\\bin"))
7066
else:
7167
raise OSError("Unsupported platform: {}".format(_PLATFORM))
7268
return [os.path.join(path, _get_shared_library_filename())

setup.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from distutils import log
2020
import fnmatch
2121
import os
22+
import platform
2223
import subprocess
2324
import sys
2425

@@ -27,12 +28,7 @@
2728
from setuptools.command import install
2829
from setuptools.command import test
2930

30-
PLATFORM_SUFFIXES = {
31-
'Linux': 'linux',
32-
'Windows': 'win64',
33-
'Darwin': 'macos',
34-
}
35-
DEFAULT_HEADERS_DIR = '~/.mujoco/include'
31+
PLATFORM = platform.system()
3632

3733
# Relative paths to the binding generator script and the output directory.
3834
AUTOWRAP_PATH = 'dm_control/autowrap/autowrap.py'
@@ -56,7 +52,28 @@ def _initialize_mjbindings_options(cmd_instance):
5652
"""Set default values for options relating to `build_mjbindings`."""
5753
# A default value must be assigned to each user option here.
5854
cmd_instance.inplace = 0
59-
cmd_instance.headers_dir = DEFAULT_HEADERS_DIR
55+
56+
candidate_paths = []
57+
if PLATFORM == 'Linux':
58+
candidate_paths.append(os.path.expanduser('~/.mujoco/mujoco-2.1.1/include'))
59+
candidate_paths.append(os.path.expanduser('~/.mujoco/include'))
60+
elif PLATFORM == 'Darwin':
61+
framework_path = 'MuJoCo.Framework/Headers'
62+
candidate_paths.append(
63+
os.path.join(os.path.expanduser('~/.mujoco'), framework_path))
64+
candidate_paths.append(os.path.join(
65+
'/Applications/MuJoCo.App/Contents/Frameworks', framework_path))
66+
elif PLATFORM == 'Windows':
67+
candidate_paths.append(os.path.join(
68+
os.environ['HOMEDRIVE'], os.environ['HOMEPATH'], 'MuJoCo\\include'))
69+
candidate_paths.append(os.path.join(
70+
os.environ['PUBLIC'], 'MuJoCo\\include'))
71+
72+
cmd_instance.headers_dir = ''
73+
for path in candidate_paths:
74+
if os.path.isdir(path):
75+
cmd_instance.headers_dir = path
76+
break
6077

6178

6279
def _finalize_mjbindings_options(cmd_instance):
@@ -175,7 +192,7 @@ def is_excluded(s):
175192

176193
setup(
177194
name='dm_control',
178-
version='0.0.416463896',
195+
version='0.0.416848645',
179196
description='Continuous control environments and MuJoCo Python bindings.',
180197
author='DeepMind',
181198
license='Apache License, Version 2.0',

0 commit comments

Comments
 (0)