Skip to content

Commit 2b571c0

Browse files
NicolasHugadrinjalali
authored andcommitted
MNT better message for pillow import error (#14027)
* better import error message for pillow * pillow -> Pillow * link to pillow page
1 parent ec35ed2 commit 2b571c0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

sklearn/externals/_pilutil.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@
6666
__all__ = ['bytescale', 'imread', 'imsave', 'fromimage', 'toimage', 'imresize']
6767

6868

69+
PILLOW_ERROR_MESSAGE = (
70+
"The Python Imaging Library (PIL) is required to load data "
71+
"from jpeg files. Please refer to "
72+
"https://pillow.readthedocs.io/en/stable/installation.html "
73+
"for installing PIL."
74+
)
75+
76+
6977
def bytescale(data, cmin=None, cmax=None, high=255, low=0):
7078
"""
7179
Byte scales an array (image).
@@ -194,8 +202,7 @@ def imread(name, flatten=False, mode=None):
194202
195203
"""
196204
if not pillow_installed:
197-
raise ImportError("The Python Imaging Library (PIL) "
198-
"is required to load data from jpeg files")
205+
raise ImportError(PILLOW_ERROR_MESSAGE)
199206

200207
im = Image.open(name)
201208
return fromimage(im, flatten=flatten, mode=mode)
@@ -281,8 +288,7 @@ def fromimage(im, flatten=False, mode=None):
281288
282289
"""
283290
if not pillow_installed:
284-
raise ImportError("The Python Imaging Library (PIL) "
285-
"is required to load data from jpeg files")
291+
raise ImportError(PILLOW_ERROR_MESSAGE)
286292

287293
if not Image.isImageType(im):
288294
raise TypeError("Input is not a PIL image.")
@@ -349,8 +355,7 @@ def toimage(arr, high=255, low=0, cmin=None, cmax=None, pal=None,
349355
350356
"""
351357
if not pillow_installed:
352-
raise ImportError("The Python Imaging Library (PIL) "
353-
"is required to load data from jpeg files")
358+
raise ImportError(PILLOW_ERROR_MESSAGE)
354359

355360
data = asarray(arr)
356361
if iscomplexobj(data):

0 commit comments

Comments
 (0)