Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mujoco_py_env: Only raise an exception if MuJocoPyEnv class is actually used #1060

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading