Skip to content

Commit

Permalink
mujoco_py_env: Only raise an exception if MuJocoPyEnv class is actual…
Browse files Browse the repository at this point in the history
…ly used (#1060)
  • Loading branch information
traversaro authored May 22, 2024
1 parent 0e8f41e commit 596bdcc
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions gymnasium/envs/mujoco/mujoco_py_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
try:
import mujoco_py
except ImportError as e:
raise error.DependencyNotInstalled(
"Could not import mujoco_py, which is needed for MuJoCo environments older than V4",
"You could either use a newer version of the environments, or install the (deprecated) mujoco-py package"
"following the instructions on their GitHub page.",
) from e
MUJOCO_PY_IMPORT_ERROR = e
else:
MUJOCO_PY_IMPORT_ERROR = None


# NOTE: duplication of analogous code in mujoco_env.py
Expand Down Expand Up @@ -214,6 +212,14 @@ def __init__(
camera_id: Optional[int] = None,
camera_name: Optional[str] = None,
):
if MUJOCO_PY_IMPORT_ERROR is not None:
raise error.DependencyNotInstalled(
f"{MUJOCO_PY_IMPORT_ERROR}. "
"Could not import mujoco_py, which is needed for MuJoCo environments older than V4",
"You could either use a newer version of the environments, or install the (deprecated) mujoco-py package"
"following the instructions on their GitHub page.",
)

logger.deprecation(
"This version of the mujoco environments depends "
"on the mujoco-py bindings, which are no longer maintained "
Expand Down

0 comments on commit 596bdcc

Please sign in to comment.