File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -116,7 +116,26 @@ 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+ RECOMMENDED_PACKAGES = {
120+ "png" : "Pillow" ,
121+ "jpg" : "Pillow" ,
122+ "jpeg" : "Pillow" ,
123+ "nii" : "nibabel or SimpleITK" ,
124+ "nii.gz" : "nibabel or SimpleITK" ,
125+ "nrrd" : "pynrrd" ,
126+ "tif" : "Pillow or tifffile" ,
127+ "tiff" : "Pillow or tifffile" ,
128+ }
129+
130+ fmt_clean = fmt .replace ("." , "" ).lower ()
131+ package_hint = RECOMMENDED_PACKAGES .get (fmt_clean , "" )
132+
133+ msg = f"No ImageWriter backend found for { fmt } ."
134+ if package_hint :
135+ msg += f" Please install '{ package_hint } ' (e.g., pip install { package_hint } )."
136+
137+ raise OptionalImportError (msg )
138+
120139 writer_tuple = ensure_tuple (avail_writers )
121140 SUPPORTED_WRITERS [fmt ] = writer_tuple
122141 return writer_tuple
You can’t perform that action at this time.
0 commit comments