From adcd5657367a00bdec6dc7873fa0710a27caa7f0 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 5 Jun 2019 08:28:27 -0400 Subject: [PATCH 1/3] better import error message for pillow --- sklearn/externals/_pilutil.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sklearn/externals/_pilutil.py b/sklearn/externals/_pilutil.py index d0fbd061538a8..c2d86a21fe599 100644 --- a/sklearn/externals/_pilutil.py +++ b/sklearn/externals/_pilutil.py @@ -66,6 +66,12 @@ __all__ = ['bytescale', 'imread', 'imsave', 'fromimage', 'toimage', 'imresize'] +PILLOW_ERROR_MESSAGE = ( + "The Python Imaging Library (PIL) is required to load data " + "from jpeg files. It can be installed with `pip install pillow`." +) + + def bytescale(data, cmin=None, cmax=None, high=255, low=0): """ Byte scales an array (image). @@ -194,8 +200,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) @@ -281,8 +286,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.") @@ -349,8 +353,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): From ce567d381772cda40a740c21c049f098431ee4fb Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 5 Jun 2019 10:17:27 -0400 Subject: [PATCH 2/3] pillow -> Pillow --- sklearn/externals/_pilutil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/externals/_pilutil.py b/sklearn/externals/_pilutil.py index c2d86a21fe599..9017dfdba7e21 100644 --- a/sklearn/externals/_pilutil.py +++ b/sklearn/externals/_pilutil.py @@ -68,7 +68,7 @@ PILLOW_ERROR_MESSAGE = ( "The Python Imaging Library (PIL) is required to load data " - "from jpeg files. It can be installed with `pip install pillow`." + "from jpeg files. It can be installed with `pip install Pillow`." ) From 5f45b5ae6de378e7a78e576bd1a4866c857ba1d5 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Thu, 6 Jun 2019 14:09:00 -0400 Subject: [PATCH 3/3] link to pillow page --- sklearn/externals/_pilutil.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sklearn/externals/_pilutil.py b/sklearn/externals/_pilutil.py index 9017dfdba7e21..a4ba5808da679 100644 --- a/sklearn/externals/_pilutil.py +++ b/sklearn/externals/_pilutil.py @@ -68,7 +68,9 @@ PILLOW_ERROR_MESSAGE = ( "The Python Imaging Library (PIL) is required to load data " - "from jpeg files. It can be installed with `pip install Pillow`." + "from jpeg files. Please refer to " + "https://pillow.readthedocs.io/en/stable/installation.html " + "for installing PIL." )