Skip to content
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

DeprecationWarning in Python 3.6 and 3.7 #3547

Closed
uri-rodberg opened this issue Jan 5, 2019 · 14 comments

Comments

Projects
None yet
4 participants
@uri-rodberg
Copy link

commented Jan 5, 2019

What did you do?

Upgrade to Pillow==5.4.0 (with pip install --upgrade -r requirements-pip-upgrade.txt on Speedy Net - https://github.com/speedy-net/speedy-net)

What did you expect to happen?

Nothing.

What actually happened?

Tests with Python 3.6 failed - https://travis-ci.org/speedy-net/speedy-net/jobs/475706499
(we run tests with deprecation warnings - python -W error::DeprecationWarning manage.py test)

DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 14.04.5 LTS (same problem with Ubuntu 16.04.5 LTS)
  • Python: 3.6.3 (same problem with Python 3.6.7 and Python 3.7.1)
  • Pillow: 5.4.0

Please include code that reproduces the issue and whenever possible, an image that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.

The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as plone, Django, or buildout, try to replicate the issue just using Pillow.

https://github.com/speedy-net/speedy-net/tree/uri_merge_with_master_2018-12-31_a

Same code except Pillow version - Pillow==5.3.0:

https://github.com/speedy-net/speedy-net/tree/uri_try_pillow_5.3.0_2019-01-05_a

Tests with Python 3.6 don't fail - https://travis-ci.org/speedy-net/speedy-net/jobs/475719810

Same problem with Python 3.7.1:

https://travis-ci.org/speedy-net/speedy-net/jobs/475722137

@hugovk

This comment has been minimized.

Copy link
Member

commented Jan 5, 2019

Pillow has supported Python 3.6 since 4.x and Python 3.7 since 5.2.0.
https://pillow.readthedocs.io/en/stable/installation.html#notes

I can't see anywhere where Pillow uses imp directly. grep -r "import imp" . and grep -r "from imp" . return nothing.

Here's your error from the logs:

0.20s$ python -W error::DeprecationWarning manage.py test
Traceback (most recent call last):
  File "manage.py", line 12, in <module>
    from django.core.management import execute_from_command_line
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/__init__.py", line 13, in <module>
    from django.core.management.base import (
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/base.py", line 17, in <module>
    from django.db.migrations.exceptions import MigrationSchemaMissing
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/migrations/__init__.py", line 2, in <module>
    from .operations import *  # NOQA
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/migrations/operations/__init__.py", line 1, in <module>
    from .fields import AddField, AlterField, RemoveField, RenameField
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 4, in <module>
    from django.db.models.fields import NOT_PROVIDED
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/models/__init__.py", line 3, in <module>
    from django.db.models.aggregates import *  # NOQA
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/models/aggregates.py", line 5, in <module>
    from django.db.models.expressions import Func, Star
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/models/expressions.py", line 6, in <module>
    from django.db.models import fields
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 14, in <module>
    from django import forms
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/forms/__init__.py", line 7, in <module>
    from django.forms.fields import *  # NOQA
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/forms/fields.py", line 17, in <module>
    from django.core import validators
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/validators.py", line 507, in <module>
    allowed_extensions=get_available_image_extensions(),
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/validators.py", line 502, in get_available_image_extensions
    Image.init()
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/PIL/Image.py", line 428, in init
    __import__("PIL.%s" % plugin, globals(), locals(), [])
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/PIL/JpegImagePlugin.py", line 41, in <module>
    from . import Image, ImageFile, TiffImagePlugin
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/PIL/TiffImagePlugin.py", line 57, in <module>
    import distutils.version
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/distutils/__init__.py", line 4, in <module>
    import imp
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/imp.py", line 33, in <module>
    DeprecationWarning, stacklevel=2)
DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
The command "python -W error::DeprecationWarning manage.py test" exited with 1.

https://travis-ci.org/speedy-net/speedy-net/jobs/475706499#L587

That show's Pillow's TiffImagePlugin.py imports distutils.version, and that the DeprecationWarning comes from distutils.

It looks similar to django-ldapdb/django-ldapdb#138, which says "the problem is the module virtualenv which tox uses" (tox-dev/tox#436). You could also add a workaround like django-ldapdb/django-ldapdb@2a7d136.

@hugovk

This comment has been minimized.

Copy link
Member

commented Jan 5, 2019

Ah yes, that's because import distutils.version was only added in 5.4.0 (in #3350).

@hugovk

This comment has been minimized.

Copy link
Member

commented Jan 5, 2019

Is there a replacement for distutils.version.StrictVersion in the stdlib?

@radarhere

This comment has been minimized.

Copy link
Member

commented Jan 6, 2019

I've created PR #3552, replacing distutils.version with simple parsing.

@radarhere radarhere changed the title Support Python 3.6, 3.7 DeprecationWarning in Python 3.6 and 3.7 Jan 6, 2019

@radarhere

This comment has been minimized.

Copy link
Member

commented Jan 6, 2019

After investigation, I believe that the deprecation warning is only occurring in virtualenv, and that regular distutils is fine. If so, then it's possible that this will be fixed for you via pypa/virtualenv#1238 once virtualenv 16.1 propagates.

uri-rodberg added a commit to speedy-net/speedy-net that referenced this issue Jan 6, 2019

@jdufresne

This comment has been minimized.

Copy link
Contributor

commented Jan 13, 2019

To me, this looks like a issue with distutils and not Pillow. I think the efforts to fix this deprecation warning should be spent there. While distutils is not recommended for use by packages, AFICT, it is not deprecated and continues to serve as the foundation for setuptools.

@hugovk

This comment has been minimized.

Copy link
Member

commented Jan 13, 2019

Agreed. There's a workaround to ignore DeprecationWarnings from distutils (eg. django-ldapdb/django-ldapdb@2a7d136).

@jdufresne

This comment has been minimized.

Copy link
Contributor

commented Jan 13, 2019

As best I can tell, this was already fixed in CPython:

python/cpython@61c3556

@radarhere

This comment has been minimized.

Copy link
Member

commented Jan 14, 2019

Just a note that pypa/virtualenv#1238 does not fix this issue after all, as the Python 3.7 job has virtualenv 16.1.0.

pypa/virtualenv#955 is an issue seeking a proper fix for this.

@hugovk

This comment has been minimized.

Copy link
Member

commented Feb 3, 2019

pypa/virtualenv#955 has been fixed by pypa/virtualenv#1289, and released in virtualenv 16.3.0.

@hugovk

This comment has been minimized.

Copy link
Member

commented Feb 18, 2019

Thanks for the report, but closing because the deprecation warning is external to Pillow, Pillow is using non-deprecated distutils in an acceptable way, and there's a workaround to silence the warning specifically from distutils.

@hugovk hugovk closed this Feb 18, 2019

@uri-rodberg

This comment has been minimized.

Copy link
Author

commented Mar 25, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.