Skip to content

Commit e65e0f8

Browse files
author
yashnaiduu
committed
improve missing writer error message
1 parent 1e3d29b commit e65e0f8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

monai/data/image_writer.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,23 @@ def resolve_writer(ext_name, error_if_not_found=True) -> Sequence:
116116
except Exception: # other writer init errors indicating it exists
117117
avail_writers.append(_writer)
118118
if not avail_writers and error_if_not_found:
119-
raise OptionalImportError(f"No ImageWriter backend found for {fmt}.")
119+
# install hints — user ko guess nahi karna padega
120+
_INSTALL_HINTS: dict = {
121+
"nii": "nibabel",
122+
"nii.gz": "nibabel",
123+
"mha": "itk",
124+
"mhd": "itk",
125+
"nrrd": "itk",
126+
"png": "pillow",
127+
"jpg": "pillow",
128+
"jpeg": "pillow",
129+
"tif": "pillow",
130+
"tiff": "pillow",
131+
"bmp": "pillow",
132+
}
133+
hint = _INSTALL_HINTS.get(fmt)
134+
extra = f" Try installing the required package: pip install {hint}" if hint else ""
135+
raise OptionalImportError(f"No ImageWriter backend found for '{fmt}'.{extra}")
120136
writer_tuple = ensure_tuple(avail_writers)
121137
SUPPORTED_WRITERS[fmt] = writer_tuple
122138
return writer_tuple

0 commit comments

Comments
 (0)