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

Fix failing import of PIL.Image.Resampling for certain Pillow versions #3992

Closed

Conversation

MaxGyver83
Copy link

Fixes #3991.

if hasattr(Image, 'Resampling'):
from PIL.Image.Resampling import LANCZOS
else:
from PIL.Image import LANCZOS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please amend to use the same form as this one:

try:
# pylint: disable=ungrouped-imports
from PIL.Image import Palette, Resampling
ADAPTIVE = Palette.ADAPTIVE
WEB = Palette.WEB
NEAREST = Resampling.NEAREST
BILINEAR = Resampling.BILINEAR
BICUBIC = Resampling.BICUBIC
LANCZOS = Resampling.LANCZOS
except ImportError:
#location for older versions:
from PIL.Image import ADAPTIVE, WEB # type: ignore
from PIL.Image import NEAREST, BILINEAR, BICUBIC, LANCZOS # type: ignore

Rationale: The “Easier to Ask Forgiveness Than Permission” (EAFP) Style

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rationale: The “Easier to Ask Forgiveness Than Permission” (EAFP) Style

I expected this 😄 But I then I didn't change to try/except because I wanted to wait first if you care at all about Ubuntu 20.04.

@totaam
Copy link
Collaborator

totaam commented Sep 7, 2023

More complete solution here:
35f77d9

@totaam totaam closed this Sep 7, 2023
@MaxGyver83
Copy link
Author

More complete solution here: 35f77d9

Great! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError: module 'PIL.Image' has no attribute 'Resampling'
2 participants