Reputation: 919
While importing, Python (Anaconda) gives the following error:
ImportError: cannot import name 'PILLOW_VERSION' from 'PIL'
I tried removing pillow
and then conda install
but the error persists.
Upvotes: 34
Views: 56624
Reputation: 2311
Downgrade pillow if you don't need latest features
pip uninstall pillow
pip install "pillow<7"
Or for anaconda,
conda install -c anaconda "pillow<7"
Upvotes: 25
Reputation: 1793
The less painful way that worked for me is using alias
from PIL import __version__ as PILLOW_VERSION
Why?
Pillow is forked from PIL 1.1.7
VERSION was removed in Pillow 6.0.0
PILLOW_VERSION was removed in Pillow 9.0.0
Use __version__ instead
When you use some older packages, they try to import PILLOW_VERSION
which is no longer available. So you'll need to use alias
.
Upvotes: 0
Reputation: 1
This is my fix to the error
Error: Could not import PILLOW_VERSION from PIL
OS: Linux 18.0 (LUBUNTU)
Python: 3.6
Resolved the issue by downgrading pillow:
pillow: 7.0.0-py36hb39fc2d_0 --> 6.1.0-py36h34e0f95_0
command: conda install pillow=6.1
Upvotes: 0
Reputation: 11218
I found one another good solution: Install Pillow-SIMD instead of Pillow.
Pillow-SIMD is "following" Pillow. Pillow-SIMD versions are 100% compatible drop-in replacements for Pillow of the same version. SIMD stands for "single instruction, multiple data" and its essence is in performing the same operation on multiple data points simultaneously by using multiple processing elements.
Homepage: https://github.com/uploadcare/pillow-simd
Benchmarks: https://python-pillow.org/pillow-perf/
Install instructions:
$ pip uninstall pillow
$ CC="cc -mavx2" pip install -U --force-reinstall pillow-simd
I checked: it has not such error and works on Pytorch/Torchvision.
You don't need to downgrade packages or change source code.
Upvotes: 1
Reputation: 4854
Downgrade your pillow to 6.1 and restart your Jupyter notebook.
Use this
conda install pillow=6.1
Upvotes: 6
Reputation: 29344
Pillow 7.0.0 removed PILLOW_VERSION
, you should use __version__
in your own code instead.
Edit (2020-01-16):
If using torchvision, this has been fixed in v0.5.0. To fix:
torchvision>=0.5.0
Old info (2020-01-09):
If using torchvision, there is a release planned this week (week 2, 2020) to fix it:
The options are:
pip install -U git+https://github.com/pytorch/vision
)pip install "pillow<7"
)Upvotes: 33
Reputation: 281
I have solved by modifying functional.py
and __init__.py
which are mentioned in error message.Error.
Modify from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
to from PIL import Image, ImageOps, ImageEnhance, __version__
in functional.py
approx line number 5.
Modify PILLOW_VERSION = __version__ = _version.__version__
to __version__ = __version__ = _version.__version__
in __init__.py
, approx line no 22.
File path:
functional.py
:C:\Users\UserName\AppData\Local\Programs\Python\Python37\Lib\site-packages\torchvision\transforms\functional.py
__init__.py
:C:\Users\UserName\AppData\Local\Programs\Python\Python37\Lib\site-packages\PIL\__init__.py
Upvotes: 11