Skip to content

[MRG] better message for pillow import error #14027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions sklearn/externals/_pilutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
__all__ = ['bytescale', 'imread', 'imsave', 'fromimage', 'toimage', 'imresize']


PILLOW_ERROR_MESSAGE = (
"The Python Imaging Library (PIL) is required to load data "
"from jpeg files. Please refer to "
"https://pillow.readthedocs.io/en/stable/installation.html "
"for installing PIL."
)


def bytescale(data, cmin=None, cmax=None, high=255, low=0):
"""
Byte scales an array (image).
Expand Down Expand Up @@ -194,8 +202,7 @@ def imread(name, flatten=False, mode=None):

"""
if not pillow_installed:
raise ImportError("The Python Imaging Library (PIL) "
"is required to load data from jpeg files")
raise ImportError(PILLOW_ERROR_MESSAGE)

im = Image.open(name)
return fromimage(im, flatten=flatten, mode=mode)
Expand Down Expand Up @@ -281,8 +288,7 @@ def fromimage(im, flatten=False, mode=None):

"""
if not pillow_installed:
raise ImportError("The Python Imaging Library (PIL) "
"is required to load data from jpeg files")
raise ImportError(PILLOW_ERROR_MESSAGE)

if not Image.isImageType(im):
raise TypeError("Input is not a PIL image.")
Expand Down Expand Up @@ -349,8 +355,7 @@ def toimage(arr, high=255, low=0, cmin=None, cmax=None, pal=None,

"""
if not pillow_installed:
raise ImportError("The Python Imaging Library (PIL) "
"is required to load data from jpeg files")
raise ImportError(PILLOW_ERROR_MESSAGE)

data = asarray(arr)
if iscomplexobj(data):
Expand Down