From 1ab9df106e172302c587e3425908306c19863951 Mon Sep 17 00:00:00 2001 From: vikasreddy11 Date: Wed, 13 May 2026 12:09:35 +0530 Subject: [PATCH 1/2] fix: improve error message when no ImageWriter backend found --- monai/data/image_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/data/image_writer.py b/monai/data/image_writer.py index cc6cdcdead..ed194a596d 100644 --- a/monai/data/image_writer.py +++ b/monai/data/image_writer.py @@ -116,7 +116,7 @@ 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}.") + raise OptionalImportError(f"No ImageWriter backend found for {fmt}. Please install pillow (`pip install pillow`)") writer_tuple = ensure_tuple(avail_writers) SUPPORTED_WRITERS[fmt] = writer_tuple return writer_tuple From a2eb5dc191787024ed1a04ad15f2420d49faddfc Mon Sep 17 00:00:00 2001 From: vikasreddy11 Date: Wed, 13 May 2026 14:19:45 +0530 Subject: [PATCH 2/2] fix: make ImageWriter error message format-aware for install hints --- monai/data/image_writer.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/monai/data/image_writer.py b/monai/data/image_writer.py index ed194a596d..ad69455b2b 100644 --- a/monai/data/image_writer.py +++ b/monai/data/image_writer.py @@ -116,7 +116,18 @@ 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}. Please install pillow (`pip install pillow`)") + hints = { + "png": "pip install pillow", + "jpg": "pip install pillow", + "jpeg": "pip install pillow", + "nii": "pip install nibabel", + "nii.gz": "pip install nibabel", + "dcm": "pip install itk", + } + hint = hints.get(fmt.lstrip(".").lower(), "pip install pillow or pip install nibabel") + raise OptionalImportError( + f"No ImageWriter backend found for {fmt}. Try: {hint}." + ) writer_tuple = ensure_tuple(avail_writers) SUPPORTED_WRITERS[fmt] = writer_tuple return writer_tuple