Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Pillow version (7.0.0) breaks torchvision (ImportError: cannot import name 'PILLOW_VERSION' from 'PIL') #1712

Closed
parsing-science opened this issue Jan 2, 2020 · 62 comments · Fixed by pyro-ppl/pyro#2345

Comments

@parsing-science
Copy link

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 (#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

@fmassa
Copy link
Member

fmassa commented Jan 2, 2020

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.

@sachinparyani
Copy link

Is there a workaround until then? Is there a version that does not depend on pillow 7.0.0?

@hugovk
Copy link

hugovk commented Jan 3, 2020

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").

@fmassa
Copy link
Member

fmassa commented Jan 3, 2020

@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

aadcock pushed a commit to aadcock/ClassyVision-2 that referenced this issue Jan 6, 2020
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 version will have Classy Vision break if torchvision is included in a file.

Torchvision will fix this next week, but then we will need our requirements to be updated. Should we use >= for our requirements rather than pinning to a specific torchvision version rather than updating with each torchvision release?

RFC since the original diff (D18450381) undid the ">=" for pytorch and mentions pinning to 0.4.2, but the reasoning expressed in the diff seems to indicate that the goal was to get off torchvision nightly builds.

For more details on PILLOW issue, see https://github.com/python-pillow/Pillow/blob/master/CHANGES.rst#700-unreleased and pytorch/vision#1712 and pytorch/vision#1718

Reviewed By: vreis

Differential Revision: D19279771

fbshipit-source-id: ff9c923e83da009fe4d9165cc2592177ae33405e
facebook-github-bot pushed a commit to facebookresearch/ClassyVision that referenced this issue Jan 6, 2020
Summary:
Pull Request resolved: fairinternal/ClassyVision#57

Pull Request resolved: #333

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 version will have Classy Vision break if torchvision is included in a file.

Torchvision will fix this next week, but then we will need our requirements to be updated. Should we use >= for our requirements rather than pinning to a specific torchvision version rather than updating with each torchvision release?

RFC since the original diff (D18450381) undid the ">=" for pytorch and mentions pinning to 0.4.2, but the reasoning expressed in the diff seems to indicate that the goal was to get off torchvision nightly builds.

For more details on PILLOW issue, see https://github.com/python-pillow/Pillow/blob/master/CHANGES.rst#700-unreleased and pytorch/vision#1712 and pytorch/vision#1718

Reviewed By: vreis

Differential Revision: D19279771

fbshipit-source-id: 880f81ca4b00dd7f541b7e2d60502b9839265422
2timesjay added a commit to 2timesjay/Ax that referenced this issue Jan 8, 2020
Summary: Address pillow_version bug blocking builds: see pytorch/vision#1712

Reviewed By: ldworkin

Differential Revision: D19312740

fbshipit-source-id: 062d720a652367921fcae6b2918092c604945f47
facebook-github-bot pushed a commit to facebook/Ax that referenced this issue Jan 8, 2020
Summary:
Pull Request resolved: #241

Address pillow_version bug blocking builds: see pytorch/vision#1712

Reviewed By: ldworkin

Differential Revision: D19312740

fbshipit-source-id: 6bfcdc822d6d56d819becf749b59d5dc2a7998e0
@mgbvox
Copy link

mgbvox commented Mar 18, 2020

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.

@mgbvox
Copy link

mgbvox commented Mar 18, 2020

UPDATE:
First downgrading pillow to 6.2.1 allowed conda install -c pytorch torchvision==0.5.0 to run.

@mgbvox
Copy link

mgbvox commented Mar 18, 2020

UPDATE:
Following that step, upgrading pillow back to the latest version didn't break anything. Might be an issue with the conda SAT solver?

@kradkahaddi
Copy link

kradkahaddi commented Mar 18, 2020

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!]

@brando90
Copy link

what is the latest version of pytorch that does not break with this pillow error?

@brando90
Copy link

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

@brando90
Copy link

seems this temp soln works:

conda install pillow=6.2.1 -y

@fmassa
Copy link
Member

fmassa commented Apr 6, 2020

Additionally, using PyTorch and torchvision from a nightly version fixes this

@DSLituiev
Copy link

Can someone update torchvision-cpu on conda channel?

conda install torchvision-cpu -c pytorch is still version 0.3.0 with this issue

@eliahuhorwitz
Copy link

Can someone update torchvision-cpu on conda channel?

conda install torchvision-cpu -c pytorch is still version 0.3.0 with this issue

Same here

@fmassa
Copy link
Member

fmassa commented Apr 21, 2020

@DSLituiev I think we don't distribute torchvision-cpu packages anymore, but instead everything is under torchvision.

cc @soumith @seemethere for thoughts

@soumith
Copy link
Member

soumith commented Apr 21, 2020

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

@craftsliu
Copy link

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!!

@fmassa
Copy link
Member

fmassa commented Apr 30, 2020

The latest release of torchvision (with the fix for PILLOW == 7) has been released

@pennarellor
Copy link

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

@saipreethamsata
Copy link

saipreethamsata commented May 1, 2020

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!

@fmassa
Copy link
Member

fmassa commented May 4, 2020

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

@axakak
Copy link

axakak commented May 14, 2020

Hi @pennarellor and @saipreethamsata

I had the same error after resolving the Pillow version issue. Restarting the Jupyter notebook kernel resolved it.

@Morpheus3000
Copy link

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.

@silvasean
Copy link

I still need to use pillow<7 workaround with:

torchvision             0.14.0.dev20220830+cpu

Is this supposed to be fixed? I see this issue is closed.

michaelbeale-IL pushed a commit to IntelLabs/distiller that referenced this issue Apr 24, 2023
fangvv pushed a commit to fangvv/distiller that referenced this issue May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.