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
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.
Is there a workaround until then? Is there a version that does not depend on pillow 7.0.0?
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").
@sachinparyani you can also install torchvision from a nightly, which also requires a pytorch from a nightly version, or wait until the next release next week
Is there a workaround until then? Is there a version that does not depend on pillow 7.0.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:
$ conda install -c conda-forge pillow==6.2.1
Is there a workaround until then? Is there a version that does not depend on pillow 7.0.0?
I downgraded pillow version to
6.2.1which seems to work without any issues. If you're using anaconda distrib, then use the below command for downgrading pillow version:$ conda install -c conda-forge pillow==6.2.1
Rather use 6.2.2, which is a security update:
$ conda install -c conda-forge pillow==6.2.2
Or:
$ conda install -c conda-forge pillow"<7.0.0"
The fact that Torchvision accepts incompatible Pillow versions is a bug in Torchvision requirements, isn't it?
You can also manually remove PILLOW_VERSION from python3.7/site-packages/torchvision/transforms/functional.py
`
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
`
Is there a workaround until then? Is there a version that does not depend on pillow 7.0.0?
I downgraded pillow version to
6.2.1which seems to work without any issues. If you're using anaconda distrib, then use the below command for downgrading pillow version:$ conda install -c conda-forge pillow==6.2.1Rather use 6.2.2, which is a security update:
$ conda install -c conda-forge pillow==6.2.2Or:
$ conda install -c conda-forge pillow"<7.0.0"
Hi there, with 6.2.2, it prompted PackageNotFoundError. Would you show your channel for 6.2.2? Thanks
Ah sorry, I guess conda doesn't have 6.2.2 yet, only pip. Use the <7 option.
If you want to use pillow of latest version, you do following
open following file.
C:\User{admin}\Anaconda3\envs\pytorch\Lib\site-packagestorchvision\transformsfunctional.py
After do comment , you should change from PILLOW_VERSION to __version__
from PIL import Image, ImageOps, ImageEnhance, __version__
Error caused:
__version__ = _version.__version__
@ynebula
If you want to use pillow of latest version, you do following
open following file.
C:\User{admin}\Anaconda3\envs\pytorch\Lib\site-packagestorchvision\transformsfunctional.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
I am still learning, so for next time I have a similar problem can you share how you figured out that PILLOW_VERSION had been replaced by version?
@ynebula
If you want to use pillow of latest version, you do following
open following file.
C:\User{admin}\Anaconda3\envs\pytorch\Lib\site-packagestorchvision\transformsfunctional.py
After do comment , you should change from PILLOW_VERSION to versionfrom 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
I am still learning, so for next time I have a similar problem can you share how you figured out that PILLOW_VERSION had been replaced by version?
I modified the "Anaconda3\envs\pytorch\Lib\site-packagestorchvision\transformsfunctional.py" file
line 5
from PIL import Image, ImageOps, ImageEnhance, version
Thank you, dear
I see your error message has more information than mine did.
I didn't have this bit #Use version instead.
version = _version.version
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?
@digantamisra98 https://github.com/pytorch/vision/issues/1712#issuecomment-570535277
@digantamisra98 expected release date is tonight
I'm having the same issue with Pillow < 7.0.0 as well (I've tried 6.2.1, 6.2.0 and 6.0.0). Torchvision has been installed via pip (version 0.4.2)
@freaky1310 for now, you can install a nightly version of torchvision following the information in https://pytorch.org/get-started/locally/ , but I would make sure that you are indeed using PILLOW 6, because my thinking is that Pillow 7 is the one being picked.
@fmassa Yeah, you're right, I thought my libraries were read from the virtual env, but the were read from the base environment instead (where I had installed the 7.0.0 version). My bad, thanks!
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
@fmassa is the release out yet?
Yes, torchvision v0.5.0 has been released with the fix:
torchvision>=0.5.0You can also manually remove PILLOW_VERSION from python3.7/site-packages/torchvision/transforms/functional.py
`
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION`
This worked for me. Was having the issue with pillow==6.1, torchvision==0.4.2.
Modify
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSIONtofrom PIL import Image, ImageOps, ImageEnhance, __version__infunctional.pyapprox line number 5.* `functional.py`:`C:\Users\UserName\AppData\Local\Programs\Python\Python37\Lib\site-packages\torchvision\transforms\functional.py`
This was enough!, thanks
Yes, torchvision v0.5.0 has been released with the fix:
- Require
torchvision>=0.5.0- If Pillow was temporarily pinned, remove the pin
pytorch 1.4.0, pillow 7.0.0, torchvision 0.5.0 works ok for me, so instead of pillow downgrading to 6.x you could update torchvision:
# use
pip install 'torchvision>=0.5.0'
# or
conda install -c pytorch 'torchvision>=0.5.0'
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!!
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?
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!!
Let us know if you have further questions!
Hi @fmassa
Thanks again for your help. Much appreciated. I updated my CUDA toolkit to 10.1. However, when I re-installed pytorch and torchvision with the command conda install pytorch torchvision cudatoolkit=10.1 -c pytorch'''
I got errorsSolving environment: failed with initial frozen solve. Retrying with flexible solve....Found Conflicts'''.
Since I updated the CUDA toolkit to 10.1, I first tried to ```conda update --all'''. But even that didn't allow me to run the above command for pytorch and torchvision installation.
Then I finally tried conda install pytorch -c pytorch''' followed byconda install torchvision -c pytorch''' and it installed pytorch-1.2.0-py3.6_cuda100_cudnn7_1''' andtorchvision-0.4.0-py36_cu100'''. So it installed torchvision 0.4.0. and not 0.5.0. So get my things running again I used the suggestion before and remove PILLOW_VERSION from the functionals.py file.
I searched for how to resolve the error "Found Conflicts!" when I ran ```conda install pytorch torchvision cudatoolkit=10.1 -c pytorch'''. But couldn't find much help. Any suggestions on how to install torchvision 0.5.0?
Thanks again!
Hi,
I would recommend creating a new conda environment, then performing the installation instructions as described in the website. You might have conflicting libraries in your system maybe?
Thanks again. I suspected that I'll have to create a new environment. I just resisted doing that since I don't know what all packages I would need in that environment and if it would again create some compatibility issues.
So should I just install pytorch + torchvision in the new environment? I guess I will also need to install, for example, numpy or opencv etc. which I might need inside the environment?
Thanks again!
HI i need some help here please if you could
i am running ubuntu 19 on raspberry pi 3B+
root@ubuntu:~/Training_SSD# uname -a
Linux ubuntu 5.3.0-1017-raspi2 #19-Ubuntu SMP Thu Jan 16 18:25:50 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux
previously i had 71.arm because i had installed raspbeian sketched and it was so much pain to install torch and torchvision on it , so i installed ubuntu instead since it provides 64 arch , and i tried every possible means to install torch and torchvision , from pip, pip3 , conda etc everything ..
but none work so few days ago i found some whl files here
https://github.com/nmilosev/pytorch-arm-builds
and by using this tutorial
https://www.youtube.com/watch?v=Ymugp9kRRT0
i was succesfully able to install it but now when i try to run my ssd.py it gives me this error
root@ubuntu:~/Training_SSD# python3 ok.py
Traceback (most recent call last):
File "ok.py", line 4, in
from data import Basetransform, VOC_CLASSES as labelmap
File "/root/Training_SSD/data/__init__.py", line 1, in
from .voc0712 import VOCDetection, AnnotationTransform, detection_collate, VOC_CLASSES
File "/root/Training_SSD/data/voc0712.py", line 14, in
import torchvision.transforms as transforms
File "/root/.local/lib/python3.7/site-packages/torchvision/__init__.py", line 2, in
from torchvision import datasets
File "/root/.local/lib/python3.7/site-packages/torchvision/datasets/__init__.py", line 9, in
from .fakedata import FakeData
File "/root/.local/lib/python3.7/site-packages/torchvision/datasets/fakedata.py", line 3, in
from .. import transforms
File "/root/.local/lib/python3.7/site-packages/torchvision/transforms/__init__.py", line 1, in
from .transforms import *
File "/root/.local/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 17, in
from . import functional as F
File "/root/.local/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 5, in
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (/usr/local/lib/python3.7/dist-packages/PIL/__init__.py)
root@ubuntu:~/Training_SSD# from .voc0712 import VOCDetection, AnnotationTransform, detection_collate, VOC_CLASSES
from: can't read /var/mail/.voc0712
root@ubuntu:~/Training_SSD# File "/root/Training_SSD/data/voc0712.py", line 14, in
-bash: syntax error near unexpected token `newline'
Would someone please help me out ?
@Umairali2562 I believe this error is not in torchvision, but in a different library.
Is there a reason to exclude CUDA 10.0 or is it just an additional effort? I need the workaround as I have control over the user installed packages or a virtual environment but not over the CUDA version, not being an admin. So the newest pytorch version is not an option. Can't imagine I am the only one with that problem.
@SaschaHornauer we follow the CUDA support from PyTorch, which is the last minor version of the two last major versions IIRC
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)
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
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
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
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
----> 1 from .transforms import *
~/anaconda3/envs/fastai/lib/python3.7/site-packages/torchvision/transforms/transforms.py in
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
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)
@kradkahaddi It's fixed in torchvision v0.5.0.
As @hugovk mentioned, you will need to update torchvision to the latest stable release to fix this.
Thank you @fmassa and @hugovk, its working like a charm now!
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").
Work like a charm!
Currently the following:
conda install -c pytorch torchvision
installs the following version of torchvision in my conda env:
torchvision 0.4.2 py37_cpu pytorch
Notably, this is NOT torchvision 0.5.0, and when I try:
conda install -c pytorch torchvision==0.5.0
Nothing happens.
UPDATE:
First downgrading pillow to 6.2.1 allowed conda install -c pytorch torchvision==0.5.0 to run.
UPDATE:
Following that step, upgrading pillow back to the latest version didn't break anything. Might be an issue with the conda SAT solver?
From what I remember, I had to use the pip install method @mgbvox . For whatever reason, torchvision 0.5.0 wasn't available on conda when I tried and from what you seem to be saying, it still isn't. And be sure to specify the version of torchvision when you install via pip. Hope this helps. [Edited for clarity] [Edit 2: I see I am a bit late with my comment. Glad you figured it out!]
what is the latest version of pytorch that does not break with this pillow error?
Let us know if you have further questions!
I have a question. What is the solution to this issue? What is the minimum version of pytorch that doesn't break it? how do I solve this?
I have pytorch 1.4.0 and it seems to still be a problem:
(automl) brandBrandoParetoopareto~/automl-meta-learning/automl/experiments $ conda list
# packages in environment at /Users/brandBrandoParetoopareto/anaconda3/envs/automl:
#
# Name Version Build Channel
absl-py 0.9.0 py37_0
asn1crypto 1.3.0 py37_0
astroid 2.3.3 py37_0
beautifulsoup4 4.8.2 py37_0
blas 1.0 mkl
bzip2 1.0.8 h1de35cc_0
c-ares 1.15.0 h1de35cc_1001
ca-certificates 2020.1.1 0
certifi 2019.11.28 py37_1
cffi 1.14.0 py37hb5b8e2f_0
chardet 3.0.4 py37_1003
conda 4.8.3 py37_0
conda-build 3.18.11 py37_0
conda-package-handling 1.6.0 py37h1de35cc_0
cryptography 2.8 py37ha12b0ac_0
filelock 3.0.12 py_0
freetype 2.9.1 hb4e5f40_0
glob2 0.7 py_0
grpcio 1.16.1 py37h044775b_1
idna 2.9 py_1
intel-openmp 2019.4 233
isort 4.3.21 py37_0
jinja2 2.11.1 py_0
jpeg 9b he5867d9_2
lazy-object-proxy 1.4.3 py37h1de35cc_0
libarchive 3.3.3 h786848e_5
libcxx 4.0.1 hcfea43d_1
libcxxabi 4.0.1 hcfea43d_1
libedit 3.1.20181209 hb402a30_0
libffi 3.2.1 h475c297_4
libgfortran 3.0.1 h93005f0_2
libiconv 1.15 hdd342a3_7
liblief 0.9.0 h2a1bed3_2
libpng 1.6.37 ha441bb4_0
libprotobuf 3.11.4 hd9629dc_0
libtiff 4.1.0 hcb84e12_0
libxml2 2.9.9 hf6e021a_1
lz4-c 1.8.1.2 h1de35cc_0
lzo 2.10 h362108e_2
markdown 3.1.1 py37_0
markupsafe 1.1.1 py37h1de35cc_0
mccabe 0.6.1 py37_1
mkl 2019.4 233
mkl-service 2.3.0 py37hfbe908c_0
mkl_fft 1.0.15 py37h5e564d8_0
mkl_random 1.1.0 py37ha771720_0
ncurses 6.2 h0a44026_0
ninja 1.9.0 py37h04f5b5a_0
numpy 1.18.1 py37h7241aed_0
numpy-base 1.18.1 py37h6575580_1
olefile 0.46 py37_0
openssl 1.1.1e h1de35cc_0
pillow 7.0.0 py37h4655f20_0
pip 20.0.2 py37_1
pkginfo 1.5.0.1 py37_0
protobuf 3.11.4 py37h0a44026_0
psutil 5.7.0 py37h1de35cc_0
py-lief 0.9.0 py37h1413db1_2
pycosat 0.6.3 py37h1de35cc_0
pycparser 2.20 py_0
pylint 2.4.4 py37_0
pyopenssl 19.1.0 py37_0
pysocks 1.7.1 py37_0
python 3.7.7 hc70fcce_0_cpython
python-libarchive-c 2.8 py37_13
pytorch 1.4.0 py3.7_0 pytorch
pytz 2019.3 py_0
pyyaml 5.3.1 py37h1de35cc_0
readline 8.0 h1de35cc_0
requests 2.23.0 py37_0
ripgrep 11.0.2 he32d670_0
ruamel_yaml 0.15.87 py37h1de35cc_0
setuptools 46.1.1 py37_0
six 1.14.0 py37_0
soupsieve 2.0 py_0
sqlite 3.31.1 ha441bb4_0
tensorboard 2.0.0 pyhb38c66f_1
tk 8.6.8 ha441bb4_0
torchvision 0.2.1 py_2 soumith
tqdm 4.43.0 py_0
urllib3 1.25.8 py37_0
werkzeug 1.0.0 py_0
wheel 0.34.2 py37_0
wrapt 1.12.1 py37h1de35cc_1
xz 5.2.4 h1de35cc_4
yaml 0.1.7 hc338f04_2
zlib 1.2.11 h1de35cc_3
zstd 1.3.7 h5bba6e5_0
seems this temp soln works:
conda install pillow=6.2.1 -y
Additionally, using PyTorch and torchvision from a nightly version fixes this
Can someone update torchvision-cpu on conda channel?
conda install torchvision-cpu -c pytorch is still version 0.3.0 with this issue
Can someone update
torchvision-cpuon conda channel?
conda install torchvision-cpu -c pytorchis still version0.3.0with this issue
Same here
@DSLituiev I think we don't distribute torchvision-cpu packages anymore, but instead everything is under torchvision.
cc @soumith @seemethere for thoughts
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=None
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").
great job,thank you!!
The latest release of torchvision (with the fix for PILLOW == 7) has been released
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
Hi all,I am also getting this error after installing torchvision 0.5.0 and the pillow 7.1.2.
ImportError : cannot import name '_HAS_OPS'
torchvision: 0.5.0
torch: 1.4.0
pillow: 7.1.2
Thanks in Advance!
Hi @pennarellor and @saipreethamsata
Those are different issues, and I would recommend opening a new issue for those.
It most probably means that you have a mismatch between the pytorch version and the torchvision versions
Hi @pennarellor and @saipreethamsata
I had the same error after resolving the Pillow version issue. Restarting the Jupyter notebook kernel resolved it.
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.
Most helpful comment
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").