Pillow cannot be loaded in python optimize (2) mode

Created on 4 Jul 2018  Â·  13Comments  Â·  Source: python-pillow/Pillow

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'
Bug

All 13 comments

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.

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.

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.

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
.

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'

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.

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

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

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

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.

Pillow 5.3.0 has just been released.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vytisb picture vytisb  Â·  4Comments

mmalenta picture mmalenta  Â·  3Comments

readyready15728 picture readyready15728  Â·  4Comments

edowson picture edowson  Â·  3Comments

Larivact picture Larivact  Â·  4Comments