{"record":{"id":"b84102aeb3ef53d4","repo":"Lightning-AI/pytorch-lightning","slug":"richmodelsummary-requires-rich-to-be-installed","errorCode":null,"errorMessage":"`RichModelSummary` requires `rich` to be installed. Install it by running `pip install -U rich`.","messagePattern":"`RichModelSummary` requires `rich` to be installed\\. Install it by running `pip install -U rich`\\.","errorType":"exception","errorClass":"ModuleNotFoundError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/rich_model_summary.py","lineNumber":62,"sourceCode":"        from lightning.pytorch import Trainer\n        from lightning.pytorch.callbacks import RichProgressBar\n\n        trainer = Trainer(callbacks=RichProgressBar())\n\n    Args:\n        max_depth: The maximum depth of layer nesting that the summary will include. A value of 0 turns the\n            layer summary off.\n        **summarize_kwargs: Additional arguments to pass to the `summarize` method.\n\n    Raises:\n        ModuleNotFoundError:\n            If required `rich` package is not installed on the device.\n\n    \"\"\"\n\n    def __init__(self, max_depth: int = 1, **summarize_kwargs: Any) -> None:\n        if not _RICH_AVAILABLE:\n            raise ModuleNotFoundError(\n                \"`RichModelSummary` requires `rich` to be installed. Install it by running `pip install -U rich`.\"\n            )\n        super().__init__(max_depth, **summarize_kwargs)\n\n    @staticmethod\n    @override\n    def summarize(\n        summary_data: list[tuple[str, list[str]]],\n        total_parameters: int,\n        trainable_parameters: int,\n        model_size: float,\n        total_training_modes: dict[str, int],\n        total_flops: int,\n        **summarize_kwargs: Any,\n    ) -> None:\n        from rich import get_console\n        from rich.table import Table\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/rich_model_summary.py#L44-L80","documentation":"RichModelSummary is a ModelSummary callback that renders the model hierarchy table using the `rich` library. On construction it checks whether rich is importable and, if not, raises ModuleNotFoundError telling the user to install rich. It is purely an optional-dependency guard.","triggerScenarios":"Instantiating RichModelSummary(max_depth=...) or passing it to Trainer(callbacks=[RichModelSummary()]) in an environment where the `rich` package is not installed (it is not a hard dependency of lightning).","commonSituations":"Fresh environments or minimal installs (pip install lightning without extras), CI docker images that prune optional deps, or using RichProgressBar/RichModelSummary after switching to a lighter virtualenv.","solutions":["pip install -U rich","Or use the plain ModelSummary callback which needs no extra dependency","Or install the relevant extras, e.g. pip install lightning[rich] if provided"],"exampleFix":"// before\ntrainer = Trainer(callbacks=[RichModelSummary()])  # ModuleNotFoundError: rich missing\n// after\n# pip install -U rich\ntrainer = Trainer(callbacks=[RichModelSummary()])","handlingStrategy":"validation","validationCode":"from lightning.fabric.utilities.imports import _RICH_AVAILABLE  # or importlib.util.find_spec\nimport importlib.util\nrich_ok = importlib.util.find_spec(\"rich\") is not None\nif not rich_ok:\n    callbacks = [ModelSummary(max_depth=2)]  # fallback\nelse:\n    callbacks = [RichModelSummary(max_depth=2)]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin `rich` in requirements if you use any Rich* callbacks","Add an import check before constructing Rich callbacks","Prefer plain ModelSummary in shared/base environments"],"tags":["rich","optional-dependency","model-summary","callback"],"backgroundTag":"missing-optional-dependency","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}