|
7 | 7 | from gym import error, logger, spaces
|
8 | 8 | from gym.spaces import Space
|
9 | 9 |
|
10 |
| -MUJOCO_PY_NOT_INSTALLED = False |
11 |
| -MUJOCO_NOT_INSTALLED = False |
12 |
| - |
13 | 10 | try:
|
14 | 11 | import mujoco_py
|
15 | 12 | except ImportError as e:
|
16 | 13 | MUJOCO_PY_IMPORT_ERROR = e
|
17 |
| - MUJOCO_PY_NOT_INSTALLED = True |
| 14 | +else: |
| 15 | + MUJOCO_PY_IMPORT_ERROR = None |
18 | 16 |
|
19 | 17 | try:
|
20 | 18 | import mujoco
|
21 | 19 | except ImportError as e:
|
22 | 20 | MUJOCO_IMPORT_ERROR = e
|
23 |
| - MUJOCO_NOT_INSTALLED = True |
| 21 | +else: |
| 22 | + MUJOCO_IMPORT_ERROR = None |
24 | 23 |
|
25 | 24 |
|
26 | 25 | DEFAULT_SIZE = 480
|
@@ -183,7 +182,7 @@ def __init__(
|
183 | 182 | camera_id: Optional[int] = None,
|
184 | 183 | camera_name: Optional[str] = None,
|
185 | 184 | ):
|
186 |
| - if MUJOCO_PY_NOT_INSTALLED: |
| 185 | + if MUJOCO_PY_IMPORT_ERROR is not None: |
187 | 186 | raise error.DependencyNotInstalled(
|
188 | 187 | f"{MUJOCO_PY_IMPORT_ERROR}. (HINT: you need to install mujoco_py, and also perform the setup instructions here: https://github.com/openai/mujoco-py/.)"
|
189 | 188 | )
|
@@ -305,7 +304,7 @@ def __init__(
|
305 | 304 | camera_id: Optional[int] = None,
|
306 | 305 | camera_name: Optional[str] = None,
|
307 | 306 | ):
|
308 |
| - if MUJOCO_NOT_INSTALLED: |
| 307 | + if MUJOCO_IMPORT_ERROR is not None: |
309 | 308 | raise error.DependencyNotInstalled(
|
310 | 309 | f"{MUJOCO_IMPORT_ERROR}. (HINT: you need to install mujoco)"
|
311 | 310 | )
|
@@ -395,15 +394,18 @@ def close(self):
|
395 | 394 |
|
396 | 395 | def _get_viewer(
|
397 | 396 | self, mode
|
398 |
| - ) -> Union["gym.envs.mujoco.Viewer", "gym.envs.mujoco.RenderContextOffscreen"]: |
| 397 | + ) -> Union[ |
| 398 | + "gym.envs.mujoco.mujoco_rendering.Viewer", |
| 399 | + "gym.envs.mujoco.mujoco_rendering.RenderContextOffscreen", |
| 400 | + ]: |
399 | 401 | self.viewer = self._viewers.get(mode)
|
400 | 402 | if self.viewer is None:
|
401 | 403 | if mode == "human":
|
402 |
| - from gym.envs.mujoco import Viewer |
| 404 | + from gym.envs.mujoco.mujoco_rendering import Viewer |
403 | 405 |
|
404 | 406 | self.viewer = Viewer(self.model, self.data)
|
405 | 407 | elif mode in {"rgb_array", "depth_array"}:
|
406 |
| - from gym.envs.mujoco import RenderContextOffscreen |
| 408 | + from gym.envs.mujoco.mujoco_rendering import RenderContextOffscreen |
407 | 409 |
|
408 | 410 | self.viewer = RenderContextOffscreen(self.model, self.data)
|
409 | 411 | else:
|
|
0 commit comments