From a51785469cdfcbaf863fc354067df3cf2a7b6c83 Mon Sep 17 00:00:00 2001 From: Talhax55z Date: Sun, 29 Mar 2026 11:20:22 -0700 Subject: [PATCH 1/3] Fix: add package install hint to ImageWriter backend error message --- 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 5b47a5e6e5..6bb34ea5b9 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 a suitable package: 'nibabel' (for .nii/.nii.gz), 'itk' (for .nrrd/.mha), or 'Pillow' (for .png/.jpg).") writer_tuple = ensure_tuple(avail_writers) SUPPORTED_WRITERS[fmt] = writer_tuple return writer_tuple From 1198bd93df3e910fef7b2d25d5e8abd512f29c7c Mon Sep 17 00:00:00 2001 From: Talhax55z Date: Sun, 29 Mar 2026 11:38:18 -0700 Subject: [PATCH 2/3] Fix: derive supported formats dynamically in ImageWriter error message --- monai/data/image_writer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/monai/data/image_writer.py b/monai/data/image_writer.py index 6bb34ea5b9..e2e9e6231f 100644 --- a/monai/data/image_writer.py +++ b/monai/data/image_writer.py @@ -116,7 +116,12 @@ 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 a suitable package: 'nibabel' (for .nii/.nii.gz), 'itk' (for .nrrd/.mha), or 'Pillow' (for .png/.jpg).") + _supported = ", ".join(sorted(SUPPORTED_WRITERS.keys())) + raise OptionalImportError( + f"No ImageWriter backend found for {fmt}. " + f"Supported formats: {_supported}. " + f"Please install a suitable package such as 'nibabel', 'itk', or 'Pillow'." + ) writer_tuple = ensure_tuple(avail_writers) SUPPORTED_WRITERS[fmt] = writer_tuple return writer_tuple From 4029c61f0c7f62e54bfb9f1c28eef9bd91587f98 Mon Sep 17 00:00:00 2001 From: Talhax55z Date: Sun, 29 Mar 2026 11:44:47 -0700 Subject: [PATCH 3/3] Fix: exclude wildcard key from supported formats hint in error message --- 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 e2e9e6231f..e0726db4fa 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: - _supported = ", ".join(sorted(SUPPORTED_WRITERS.keys())) + _supported = ", ".join(sorted(k for k in SUPPORTED_WRITERS.keys() if k != "*")) raise OptionalImportError( f"No ImageWriter backend found for {fmt}. " f"Supported formats: {_supported}. "