Could not import PILLOW_VERSION from PIL

被刻印的时光 ゝ 提交于 2020-02-23 09:15:42

问题


While importing, Python(anaconda) gives the following error:

ImportError: cannot import name 'PILLOW_VERSION' from 'PIL'

I tried removing pillow and then conda install but the error persists. Please help


回答1:


Pillow 7.0.0 removed PILLOW_VERSION, you should use __version__ in your own code instead.

  • https://pillow.readthedocs.io/en/stable/deprecations.html#pillow-version-constant

Edit (2020-01-16):

If using torchvision, this has been fixed in v0.5.0. To fix:

  1. Require torchvision>=0.5.0
  2. If Pillow was temporarily pinned, remove the pin

Old info (2020-01-09):

If using torchvision, there is a release planned this week (week 2, 2020) to fix it:

  • https://github.com/pytorch/vision/issues/1712#issuecomment-570286349

The options are:

  • wait for the new torchvision release
  • use the master version of torchvision (eg. pip install -U git+https://github.com/pytorch/vision)
  • install torchvision from a nightly, which also requires a pytorch from a nightly version
  • or install Pillow<7 (eg. pip install "pillow<7")



回答2:


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




回答3:


Downgrade pillow if you don't need latest features

pip install pillow==6.1




回答4:


  • Currently using torchvision==0.4.2 and this solved my problem.
  • Downgrade your pillow to 6.1 and restart your Jupyter notebook.

    Use this

    conda install pillow=6.1



来源:https://stackoverflow.com/questions/59659146/could-not-import-pillow-version-from-pil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!