python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.14k stars 2.21k forks source link

Pillow cannot be loaded in python optimize (2) mode #3231

Closed Menollo closed 6 years ago

Menollo commented 6 years ago

What did you do?

I was loading the PIL module with 'import PIL' when running Python with PYTHONOPTIMZE=2 (or python -OO).

What did you expect to happen?

I Expected the PIL/Pillow Library to be imported.

What actually happened?

I received an exception: AttributeError: 'NoneType' object has no attribute 'format'

What versions of Pillow and Python are you using?

Pillow 5.2.0 / Python 3.6.5

Reason:

PYTHONOPTIMIZE=2 / python -OO strips the doc variable.

Example:

create a file called test.py with only import PIL

import PIL

Execute it with python in optimize mode

python -OO test.py

You will receive the following exception:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import PIL
  File "/usr/lib/python3.6/site-packages/PIL/__init__.py", line 27, in <module>
    __doc__ = __doc__.format(__version__)  # include version in docstring
AttributeError: 'NoneType' object has no attribute 'format'
hugovk commented 6 years ago

Thanks, as you noted, this was caused by 36be37c5c56ae042b3a35e3abf3d59061c0e1162 in https://github.com/python-pillow/Pillow/pull/3218.

The version isn't essential there, let's just remove it.

hugovk commented 6 years ago

Please see PR https://github.com/python-pillow/Pillow/pull/3233.

mrocklin commented 6 years ago

This is affecting test suites and CI of downstream projects. Any chance of a rapid bugfix release? "No" is a fine answer, I just need to plan accordingly.

hugovk commented 6 years ago

Not sure this is critical enough for a point release, normally reserved for security, installation or critical bug fixes.

Releases are quarterly, the last one just went on 2018-07-01, next one is due on 2018-10-01.

mrocklin commented 6 years ago

OK thanks. I'll patch downstream them.

On Fri, Jul 6, 2018 at 8:09 AM Hugo notifications@github.com wrote:

Not sure this is critical enough for a point release, normally reserved for security, installation or critical bug fixes.

Releases are quarterly, the last one just went on 2018-07-01, next one is due on 2018-10-01.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/python-pillow/Pillow/issues/3231#issuecomment-403015343, or mute the thread https://github.com/notifications/unsubscribe-auth/AASszD4YPgE3i0N-h_HwJdKHYcCeZItiks5uD1NxgaJpZM4VCj7O .

hugovk commented 6 years ago

The minimal fix to patch the problem introduced in 5.2.0 is https://github.com/python-pillow/Pillow/pull/3233/commits/92a39bcd9bd78e41f24c1d85f43650bbb5985f1f.

mrocklin commented 6 years ago

Well, I might actually push back a bit about timelines. This breaks libraries like scipy

mrocklin@carbon:~/workspace/dask$ pip install pillow --upgrade > /dev/null
mrocklin@carbon:~/workspace/dask$ export PYTHONOPTIMIZE=2
mrocklin@carbon:~/workspace/dask$ python -c "import scipy.stats"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/mrocklin/Software/anaconda/envs/27/lib/python2.7/site-packages/scipy/stats/__init__.py", line 345, in <module>
    from .stats import *
  File "/home/mrocklin/Software/anaconda/envs/27/lib/python2.7/site-packages/scipy/stats/stats.py", line 171, in <module>
    from . import distributions
  File "/home/mrocklin/Software/anaconda/envs/27/lib/python2.7/site-packages/scipy/stats/distributions.py", line 10, in <module>
    from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
  File "/home/mrocklin/Software/anaconda/envs/27/lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.py", line 16, in <module>
    from scipy.misc import doccer
  File "/home/mrocklin/Software/anaconda/envs/27/lib/python2.7/site-packages/scipy/misc/__init__.py", line 100, in <module>
    from .pilutil import *
  File "/home/mrocklin/Software/anaconda/envs/27/lib/python2.7/site-packages/scipy/misc/pilutil.py", line 19, in <module>
    from PIL import Image, ImageFilter
  File "/home/mrocklin/Software/anaconda/envs/27/lib/python2.7/site-packages/PIL/__init__.py", line 27, in <module>
    __doc__ = __doc__.format(__version__)  # include version in docstring
AttributeError: 'NoneType' object has no attribute 'format'
bryevdv commented 6 years ago

This also breaks Bokeh's CI build as well, we have a test to maintain that library modules can always be imported with -OO and now that we have added PIL as a dependency, they are failing. I would also request a more aggressive schedule to release a fix.

stonebig commented 6 years ago

if it's a problem to do a patch release, would it be possible to just remove the 5.2 version from pypi ?

ZippoLag commented 6 years ago

It's a bit puzzling, but 5.2.0 works just fine on Windows, however the linux version seems to have this problem.

kg-2 commented 6 years ago

5.2 breaks reportlab for me on Windows when optimized. python 3.6.3

hugovk commented 6 years ago

PR https://github.com/python-pillow/Pillow/pull/3233 is merged and it will be in release 5.3.0 due on 2018-10-01.

hugovk commented 5 years ago

Pillow 5.3.0 has just been released.