From b809c770678292687155013caa66cb034b7d9e38 Mon Sep 17 00:00:00 2001 From: yashnaiduu Date: Mon, 2 Mar 2026 00:06:19 +0530 Subject: [PATCH 1/2] fix: print install hint when no suitable ImageWriter found When resolve_writer() fails to find a backend for a given file extension, the error was generic. Added a format-to-package lookup that appends an install hint (e.g. pip install nibabel) for common formats. Fixes #7980 Signed-off-by: yashnaiduu --- monai/data/image_writer.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/monai/data/image_writer.py b/monai/data/image_writer.py index 5b47a5e6e5..667bf3e60c 100644 --- a/monai/data/image_writer.py +++ b/monai/data/image_writer.py @@ -116,7 +116,23 @@ def resolve_writer(ext_name, error_if_not_found=True) -> Sequence: except Exception: # other writer init errors indicating it exists avail_writers.append(_writer) if not avail_writers and error_if_not_found: - raise OptionalImportError(f"No ImageWriter backend found for {fmt}.") + # map common extensions to their required package + install_hints: dict = { + "nii": "nibabel", + "nii.gz": "nibabel", + "mha": "itk", + "mhd": "itk", + "nrrd": "itk", + "png": "pillow", + "jpg": "pillow", + "jpeg": "pillow", + "tif": "pillow", + "tiff": "pillow", + "bmp": "pillow", + } + hint = install_hints.get(fmt) + extra = f" Try installing the required package: pip install {hint}" if hint else "" + raise OptionalImportError(f"No ImageWriter backend found for '{fmt}'.{extra}") writer_tuple = ensure_tuple(avail_writers) SUPPORTED_WRITERS[fmt] = writer_tuple return writer_tuple From 6a5238f537ab1441a7de3411a2298ad3060e5006 Mon Sep 17 00:00:00 2001 From: yashnaiduu Date: Mon, 2 Mar 2026 00:11:16 +0530 Subject: [PATCH 2/2] clean up unnecessary comments Signed-off-by: yashnaiduu --- monai/data/image_writer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/monai/data/image_writer.py b/monai/data/image_writer.py index 667bf3e60c..2463b99cfd 100644 --- a/monai/data/image_writer.py +++ b/monai/data/image_writer.py @@ -116,7 +116,6 @@ def resolve_writer(ext_name, error_if_not_found=True) -> Sequence: except Exception: # other writer init errors indicating it exists avail_writers.append(_writer) if not avail_writers and error_if_not_found: - # map common extensions to their required package install_hints: dict = { "nii": "nibabel", "nii.gz": "nibabel",