Spaces:
Sleeping
Sleeping
Download src/cdpr/learn/_lazy.py from JoeTach/cdpr-simulator: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/spaces/JoeTach/cdpr-simulator/resolve/main/src/cdpr/learn/_lazy.py
- Command line
-
hf download hf://spaces/JoeTach/cdpr-simulator/src/cdpr/learn/_lazy.py
-
curl -L -o _lazy.py https://huggingface.co/spaces/JoeTach/cdpr-simulator/resolve/main/src/cdpr/learn/_lazy.py
1.16 kB
| """Lazy-import helpers for the learning extras. | |
| Each function returns the imported module if available; otherwise raises | |
| ``ImportError`` with the exact pip command needed to fix it. This keeps | |
| the scientific core importable on machines without PyTorch / SB3 / Gym. | |
| """ | |
| from __future__ import annotations | |
| from types import ModuleType | |
| def require_torch() -> ModuleType: | |
| try: | |
| import torch | |
| except ImportError as exc: | |
| raise ImportError( | |
| "The learning layer needs PyTorch. Install with: pip install 'cdpr[learn]'" | |
| ) from exc | |
| return torch | |
| def require_gymnasium() -> ModuleType: | |
| try: | |
| import gymnasium | |
| except ImportError as exc: | |
| raise ImportError( | |
| "The RL environment needs Gymnasium. Install with: pip install 'cdpr[learn]'" | |
| ) from exc | |
| return gymnasium | |
| def require_stable_baselines3() -> ModuleType: | |
| try: | |
| import stable_baselines3 | |
| except ImportError as exc: | |
| raise ImportError( | |
| "The SB3 wrappers need Stable-Baselines3. " | |
| "Install with: pip install 'cdpr[rl]'" | |
| ) from exc | |
| return stable_baselines3 | |