vision: New Pillow version (7.0.0) breaks torchvision (ImportError: cannot import name 'PILLOW_VERSION' from 'PIL')
Hi, it looks like Pillow released version 7.0.0 so I can no longer import torchvision without getting this error: ImportError: cannot import name 'PILLOW_VERSION' from 'PIL'
Pinning to Pillow 6.2.1 fixes the issue.
I see that you fixed this for a future torchvision release (https://github.com/pytorch/vision/pull/1501). Do you know when this will be released? If it will be awhile, could the version of Pillow be pinned to be less than 7.0.0 in the meantime?
Thanks.
Versions: torch: 1.3.1 torchvision: 0.4.2 Pillow: 7.0.0
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 83
- Comments: 62 (15 by maintainers)
Commits related to this issue
- Update torchvision versioning Summary: We are hitting an issue where torchvision current release is broken with the current version of PIL. So in OSS land, users with 0.4.2 who update their PIL versi... — committed to aadcock/ClassyVision-2 by deleted user 4 years ago
- Update torchvision versioning (#57) Summary: Pull Request resolved: https://github.com/fairinternal/ClassyVision/pull/57 Pull Request resolved: https://github.com/facebookresearch/ClassyVision/pull/... — committed to facebookresearch/ClassyVision by deleted user 4 years ago
- Pillow version fix Summary: Address pillow_version bug blocking builds: see https://github.com/pytorch/vision/issues/1712 Reviewed By: ldworkin Differential Revision: D19312740 fbshipit-source-id:... — committed to 2timesjay/Ax by 2timesjay 4 years ago
- Pillow version fix (#241) Summary: Pull Request resolved: https://github.com/facebook/Ax/pull/241 Address pillow_version bug blocking builds: see https://github.com/pytorch/vision/issues/1712 Revie... — committed to facebook/Ax by 2timesjay 4 years ago
- Pillow fix for torchvision breakage Trying to fix https://github.com/pytorch/vision/issues/1714, https://github.com/pytorch/vision/issues/1712 — committed to microsoft/seismic-deeplearning by sharatsc 4 years ago
- Force Solve Torchvision Dependency Fail for Pillow Refer to issue - https://github.com/pytorch/vision/issues/1712#issuecomment-574564456 — committed to digantamisra98/Mish by digantamisra98 4 years ago
- Fix requirements.txt - due to torchvision/pillow mismatch Temp patch until moving to torchvision 0.5. See https://github.com/pytorch/vision/issues/1712#issuecomment-575036523 — committed to IntelLabs/distiller by nzmora 4 years ago
- Neptune integration (#571) * added neptune support * added neptune to contrib, formated code < 79 lenght * dropped isort * added neptune to isort * added lib in alphabetical order to isor... — committed to catalyst-team/catalyst by jakubczakon 4 years ago
- Neptune integration (#571) * added neptune support * added neptune to contrib, formated code < 79 lenght * dropped isort * added neptune to isort * added lib in alphabetical order to isort * add... — committed to catalyst-team/catalyst by deleted user 4 years ago
- Update torchvision to work with latest Pillow 7 Re: https://github.com/pytorch/vision/issues/1712 — committed to hugovk/SteganoGAN by hugovk 4 years ago
- Downgrade PIL version due to breaking changes https://github.com/pytorch/vision/issues/1712 Recently PIL 7 removed `PILLOW_VERSION`. This affects `torchvision: 0.4.2` as described in the pytorch i... — committed to krishnakalyan3/fastai2 by krishnakalyan3 4 years ago
- Fix requirements.txt - due to torchvision/pillow mismatch Temp patch until moving to torchvision 0.5. See https://github.com/pytorch/vision/issues/1712#issuecomment-575036523 — committed to OZA15015/pruning by nzmora 4 years ago
- Fix requirements.txt - due to torchvision/pillow mismatch Temp patch until moving to torchvision 0.5. See https://github.com/pytorch/vision/issues/1712#issuecomment-575036523 — committed to IntelLabs/distiller by nzmora 4 years ago
- Fix requirements.txt - due to torchvision/pillow mismatch Temp patch until moving to torchvision 0.5. See https://github.com/pytorch/vision/issues/1712#issuecomment-575036523 — committed to fangvv/distiller by nzmora 4 years ago
Until the new torchvision release is out, the workaround is either to use the master version of torchvision (eg.
pip install -U git+https://github.com/pytorch/vision
), or Pillow<7 (eg.pip install "pillow<7"
).I still need to use
pillow<7
workaround with:Is this supposed to be fixed? I see this issue is closed.
This might be late, but for fellow travelers led to this by Google, a simpler workaround for this, instead of downgrading can be done by patching the torchvision/transforms/functional.py file. If you remove the PILLOW_VERSION import from the import and then replace PILLOW_VERSION with PIL.version in line 727, then it works without a downgrade. Official PIL docs recommends using version instead.
Hi,
Thanks for the report!
We will be releasing a new version of PyTorch and torchvision early next week, so this should be soon fixed.
As such, I’m closing the issue, but let me know if you have further questions.
pytorch 1.4.0
,pillow 7.0.0
,torchvision 0.5.0
works ok for me, so instead ofpillow
downgrading to 6.x you could updatetorchvision
:Yes, torchvision v0.5.0 has been released with the fix:
torchvision>=0.5.0
I downgraded pillow version to
6.2.1
which seems to work without any issues. If you’re using anaconda distrib, then use the below command for downgrading pillow version:Hi @pennarellor and @saipreethamsata
I had the same error after resolving the Pillow version issue. Restarting the Jupyter notebook kernel resolved it.
seems this temp soln works:
This was enough!, thanks
The fact that Torchvision accepts incompatible Pillow versions is a bug in Torchvision requirements, isn’t it?
Hi,
Firstly, thanks a lot for some great advice above to resolve the PILLOW_VERSION problem. However, I’m still unable to resolve the issue with the torchvision==0.5.0, because I can’t seem to install torchvision version 0.5.0.
I tried to install torchvision==0.5.0 with conda. But everytime the version installed is torchvision==0.3.0. I tried to uninstall and conda install -c ‘torchvision>=0.5.0’ multiple times but doesn’t seem to install torchvision 0.5.0. Is it because my cuda toolkit version is 9.0? Can somebody please help? I spent hours trying to get this working without having to remove the PILLOW_VERSION from the functional.py as mentioned above in one solution. Thanks much for any suggestions and tips. I’d really appreciate!!
@kradkahaddi It’s fixed in torchvision v0.5.0.
Hi @fmassa Thanks so much for getting back. I suspected that it must be CUDA 9.0. I didn’t update the toolkit and used the workaround mentioned before to remove the PILLOW_VERSION. It seemed to work. But you are right, I should update the CUDA toolkit and then install torchvision 0.5.0. Thanks again for your help!!
This worked for me. Was having the issue with
pillow==6.1
,torchvision==0.4.2
.@digantamisra98 expected release date is tonight
If you want to use pillow of latest version, you do following
open following file. C:\User{admin}\Anaconda3\envs\pytorch\Lib\site-packages\torchvision\transforms\functional.py After do comment , you should change from PILLOW_VERSION to __version__ #from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION from PIL import Image, ImageOps, ImageEnhance, __version__
Error caused: #VERSION was removed in Pillow 6.0.0. #PILLOW_VERSION was removed in Pillow 7.0.0. #Use version instead. __version__ = _version.version
Hi all, I upgraded to torchvision 0.5.0 and the pillow 7.0.0 issue is solved, but now I get this error
ImportError: cannot import name '_HAS_OPS' from 'torchvision.extension'
torch: 1.4.0 torchvision: 0.5.0 pillow: 7.0.0
we dont distributed torchvision-cpu packges, but we do distributed Conda CPU-only torchvision packages. They are installable via a label:
conda install pytorch torchvision cpuonly -c pytorch
This is documented on pytorch.org , in the install selector, just select CUDA=NoneThank you @fmassa and @hugovk, its working like a charm now!
As @hugovk mentioned, you will need to update torchvision to the latest stable release to fix this.
Hello, Was this issue fixed? I am still getting an error here while importing torchvision. I am using version 0.4.2 (build channel: cuda100py37hecfc37a_0) and getting an Import error.
PIL version is 7.0.0 and build channel is py37hb39fc2d_0
Here are the pytorch versions and build channels _pytorch_select is 0.2 with build channel gpu_0
pytorch version is 1.3.1 with build channel cuda100py37h53c1284_0
Pasting error log below for reference
ImportError Traceback (most recent call last) <ipython-input-1-6842f2896ae5> in <module> 9 import torch.nn.functional as F 10 from torch.utils.data import DataLoader, Dataset, TensorDataset —> 11 from torchvision import transforms, utils 12 from skimage import io, transform 13
~/anaconda3/envs/fastai/lib/python3.7/site-packages/torchvision/init.py in <module> 2 3 from torchvision import models ----> 4 from torchvision import datasets 5 from torchvision import ops 6 from torchvision import transforms
~/anaconda3/envs/fastai/lib/python3.7/site-packages/torchvision/datasets/init.py in <module> 7 from .svhn import SVHN 8 from .phototour import PhotoTour ----> 9 from .fakedata import FakeData 10 from .semeion import SEMEION 11 from .omniglot import Omniglot
~/anaconda3/envs/fastai/lib/python3.7/site-packages/torchvision/datasets/fakedata.py in <module> 1 import torch 2 from .vision import VisionDataset ----> 3 from … import transforms 4 5
~/anaconda3/envs/fastai/lib/python3.7/site-packages/torchvision/transforms/init.py in <module> ----> 1 from .transforms import *
~/anaconda3/envs/fastai/lib/python3.7/site-packages/torchvision/transforms/transforms.py in <module> 15 import warnings 16 —> 17 from . import functional as F 18 19 if sys.version_info < (3, 3):
~/anaconda3/envs/fastai/lib/python3.7/site-packages/torchvision/transforms/functional.py in <module> 3 import sys 4 import math ----> 5 from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION 6 try: 7 import accimage
ImportError: cannot import name ‘PILLOW_VERSION’ from ‘PIL’ (/home/aash/anaconda3/envs/fastai/lib/python3.7/site-packages/PIL/init.py)
@SaschaHornauer we follow the CUDA support from PyTorch, which is the last minor version of the two last major versions IIRC
Hi @skudekar
We don’t provide binaries anymore for CUDA 9.0, only for CUDA 9.2 and CUDA 10.1. That’s the reason why you are not being able to update torchvision.
Can you try installing a newer version of the CUDA toolkit?
@digantamisra98 https://github.com/pytorch/vision/issues/1712#issuecomment-570535277
When will the new TorchVision version containing the fix for Pillow dependency be out. My build via CircleCI is failing due to the same? Can I force solve this for the time being?
You can also manually remove PILLOW_VERSION from python3.7/site-packages/torchvision/transforms/functional.py ` from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
`
Rather use 6.2.2, which is a security update:
Or: