ImportError: cannot import name 'PILLOW_VERSION' from 'PIL'
Fixes ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' Use when Pillow 7+ and something imports PILLOW_VERSION Not for: `No module named 'PIL'` (Pillow is not installed at all)
How to fix ImportError: cannot import name 'PILLOW_VERSION' from 'PIL'
PILLOW_VERSION was removed from Pillow. In your own code replace from PIL import PILLOW_VERSION with from PIL import __version__. If the traceback is inside a library (old torchvision, invertransforms, etc.), upgrade that library; downgrading Pillow is only a stopgap.
The exact error
ImportError: cannot import name 'PILLOW_VERSION' from 'PIL'Fix it
Your code:
from PIL import PILLOW_VERSION->from PIL import __version__. Expected: import works on Pillow 10+A library:
pip install -U [library]. Expected: upstream fixed the importStopgap only:
pip install "pillow<7". Expected: old Pillow has the constant (not recommended)
When this applies
Pillow 7+ and something imports PILLOW_VERSION
When this does NOT apply
No module named 'PIL' (Pillow is not installed at all)
Versions
Pillow >= 7 (removed), >= 10 (fully gone)
Why it happens
Pillow deprecated the constant in 5.2, removed it in 7.0.
Edge cases
torchvision below 0.5 is the most common carrier of this; upgrade torchvision with torch.