Cannot import name 'PILLOW_VERSION' from 'PIL'

when I execute -

from torchvision import datasets, transforms

I get the following error -

ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (C:\ProgramData\Anaconda3\lib\site-packages\PIL\

How can I fix this?

It appears that this is being fixed by PyTorch -

I found a work around by reverting PIL to 6.2.1


As Aditya1 noted,
conda install pillow=6.2.1
will get around this for now.

what is the minimum version of pytorch and torchvision for this error to stop?

I was having an odd error:

Traceback (most recent call last):
  File "", line 53, in <module>
  File "", line 35, in download_and_extract_miniImagenet
    from torchvision.datasets.utils import download_file_from_google_drive, extract_archive
  File "/Users/brandBrandoParetoopareto/opt/miniconda3/lib/python3.7/site-packages/torchvision/", line 2, in <module>
    from torchvision import datasets
  File "/Users/brandBrandoParetoopareto/opt/miniconda3/lib/python3.7/site-packages/torchvision/datasets/", line 9, in <module>
    from .fakedata import FakeData
  File "/Users/brandBrandoParetoopareto/opt/miniconda3/lib/python3.7/site-packages/torchvision/datasets/", line 3, in <module>
    from .. import transforms
  File "/Users/brandBrandoParetoopareto/opt/miniconda3/lib/python3.7/site-packages/torchvision/transforms/", line 1, in <module>
    from .transforms import *
  File "/Users/brandBrandoParetoopareto/opt/miniconda3/lib/python3.7/site-packages/torchvision/transforms/", line 16, in <module>
    from . import functional as F
  File "/Users/brandBrandoParetoopareto/opt/miniconda3/lib/python3.7/site-packages/torchvision/transforms/", line 5, in <module>
    from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (/Users/brandBrandoParetoopareto/opt/miniconda3/lib/python3.7/site-packages/PIL/

I installed pytorch and torchvision:

$ conda list
# packages in environment at /Users/brandBrandoParetoopareto/opt/miniconda3:
# Name                    Version                   Build  Channel
_pytorch_select           0.1                       cpu_0  
asn1crypto                1.3.0                    py37_0  
beautifulsoup4            4.8.2                    py37_0  
blas                      1.0                         mkl  
bzip2                     1.0.8                h1de35cc_0  
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  
idna                      2.8                      py37_0  
intel-openmp              2019.4                      233  
jinja2                    2.11.1                     py_0  
jpeg                      9b                   he5867d9_2  
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  
libtiff                   4.1.0                hcb84e12_0  
libxml2                   2.9.9                hf6e021a_1  
lz4-c                         h1de35cc_0  
lzo                       2.10                 h362108e_2  
markupsafe                1.1.1            py37h1de35cc_0  
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                           py37_0  
psutil                    5.7.0            py37h1de35cc_0  
py-lief                   0.9.0            py37h1413db1_2  
pycosat                   0.6.3            py37h1de35cc_0  
pycparser                 2.19                     py37_0  
pyopenssl                 19.1.0                   py37_0  
pysocks                   1.7.1                    py37_0  
python                    3.7.6                h359304d_2  
python-libarchive-c       2.8                     py37_13                2                       py37_10  
pytorch                   1.4.0           cpu_py37hf9bb1df_0  
pytz                      2019.3                     py_0  
pyyaml                    5.3.1            py37h1de35cc_0  
readline                  7.0                  h1de35cc_5  
requests                  2.22.0                   py37_1  
ripgrep                   11.0.2               he32d670_0  
ruamel_yaml               0.15.87          py37h1de35cc_0  
setuptools                45.2.0                   py37_0  
six                       1.14.0                   py37_0  
soupsieve                 2.0                        py_0  
sqlite                    3.31.1               ha441bb4_0  
tk                        8.6.8                ha441bb4_0  
torchvision               0.2.1                      py_2    soumith
tqdm                      4.42.1                     py_0  
urllib3                   1.25.8                   py37_0  
wheel                     0.34.2                   py37_0  
xz                        5.2.4                h1de35cc_4  
yaml                      0.1.7                hc338f04_2  
zlib                      1.2.11               h1de35cc_3  
zstd                      1.3.7                h5bba6e5_0  

and I’ve had this script work in the past before I just don’t know what might be wrong…

saw this too…

downgrade to

conda install pillow=6.2.1

to temporarily solve this issue.

1 Like


I have just installed PyTorch 1.12 on a EC2 DL AMI (originally PyTorch 1.1 DL AMI) using conda using the command on PyTorch page as below, and now see this error message upon importing torchvision. After installation, PIL version is 9.1.1.

conda create -n pytorch12 python=3.10.5 ipython
conda install pytorch torchvision torchaudio cudatoolkit=11.6 -c pytorch -c conda-forge

The original conda env with PyTorch 1.11 works fine. Interestingly, the AMI and PyTorch 1.1 env have PIL version 9.2.0. Installing PyTorch 1.12 with the above command seems to downgrade PIL to 9.1.1.

Is there a clean solution? How should I install PyTorch 1.12 in a conda env?

Update: Solved
I used pip to install pytorch and also specified PIL (pillow) version as 9.2.0 and the issue was solved.

conda create -n pytorch12 python=3.10.5 ipython
pip3 install torch torchvision torchaudio 'pillow==9.2.0' --extra-index-url