diff --git a/src/lightning_utilities/core/imports.py b/src/lightning_utilities/core/imports.py index 029f4ae1..5e28744b 100644 --- a/src/lightning_utilities/core/imports.py +++ b/src/lightning_utilities/core/imports.py @@ -127,8 +127,8 @@ def __init__(self, requirement: Optional[str] = None, module: Optional[str] = No def _check_requirement(self) -> None: assert self.requirement # noqa: S101; needed for typing - req = Requirement(self.requirement) try: + req = Requirement(self.requirement) pkg_version = Version(_version(req.name)) if req.specifier.contains(pkg_version): self.available = True @@ -136,9 +136,9 @@ def _check_requirement(self) -> None: else: self.available = False self.message = f"Requirement {self.requirement!r} not met. Current version: {pkg_version}" - except (PackageNotFoundError, InvalidVersion): + except (PackageNotFoundError, InvalidVersion) as ex: self.available = False - self.message = f"Package not found: {req.name}. HINT: Try running `pip install -U {self.requirement!r}`" + self.message = f"{ex.__class__.__name__}: {ex}. HINT: Try running `pip install -U {self.requirement!r}`" req_include_version = any(c in self.requirement for c in "=<>") if not req_include_version or self.module is not None: module = self.requirement if self.module is None else self.module