I have run the same code(with packages I needed) before and it worked, not sure what's happening now. This show the error,
AttributeError: module 'PIL.Image' has no attribute 'Resampling'
. Probably it's small issue, but I can't figure it out, I am working in databricks.
I had the same problem. The easy way is use the old version of Pillow.
pip install Pillow==9.0.0
And your code should work.
Note: You can also use
pip install --ignore-installed Pillow==9.0.0
If for some reason, pip is refusing to install it. Note, however, that it can break dependencies, so use it only as a last resort.
I had the same problem and found that I need to replace PIL.Image.Resampling.BICUBIC
with PIL.Image.BICUBIC
.
I am using pillow version 7.1.2
from PIL import Image
im = Image.open('image.png')
im2 = im.resize((512,512),resample=Image.BICUBIC)
display(im2)
I find that forcing the use of a particular Pillow version may break other packages.
Another solution that works for any Pillow version and avoids deprecation warnings is to insert the code:
import PIL.Image
if not hasattr(PIL.Image, 'Resampling'): # Pillow<9.0
PIL.Image.Resampling = PIL.Image
# Now PIL.Image.Resampling.BICUBIC is always recognized.
pip freeze
to find out what those versions are, so they can be used for production. This is a pretty good place to start: packaging.python.org/en/latest/tutorials/installing-packages –
Inviolate The resampling enums were seemingly added in Pillow 9.1.0 (released 3 days ago) via this pull request.
I would imagine your Databricks environment has a different verison.
my way to fix it: pip install --ignore-installed Pillow==9.3.0
--ignore-installed
though. –
Pyrrolidine Same happened when I upgraded some module. I just restarted runtime and it helped.
In my case, pip install Pillow==9.1.0
is suitable for my code
If you don't want to downgrade the Pillow
library, you can try to install the latest matplotlib
:
python3 -m pip install matplotlib==3.7.1
Resampling enum (and other new enums) can be added here. https://github.com/python/typeshed/blob/main/stubs/Pillow/PIL/Image.pyi
If you've just installed a Python program with pip
and it raises this error, it's probably because of a conflict with something you've previously installed. In this case pip install Pillow==9.0.0
did not work for me (and it may break something else).
Creating a clean venv for that program should fix it:
$ mkdir frobnicator
$ cd frobnicator
$ python -m venv venv
$ source venv/bin/activate
(venv) $ pip install frobnicator
(venv) $ frobnicator ...
I had the same issue occur in Google Colab.
I first installed Pillow:
!pip install pillow
After that I still got the error, until I restarted the Runtime. Once the runtime was restarted, the error went away.
Well, I had the same issue, so I went with simplest solution by TADA!@! removing it. also it can be fixed with changing it to Image.BICUBIC. results are just the same for me. working code with same valid results.
© 2022 - 2024 — McMap. All rights reserved.