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

Original Address

Categories --Pytorch

  • An error

I was at the time of Digital Recognition with Pytorch, because the program is introduced with torchvisionthis module, follow the prompts to find an error in the past, we found an error occurred in the torchvision \ transforms \ functional.py in on this one

from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
  • the reason

Checked the reasons is because

In 7.0.0:

PILLOW_VERSION has been removed. Use __version__ instead.

Quoted from https://github.com/python-pillow/Pillow/issues/4130#issuecomment-570453802

I tried for torchvisionthis module has been updated, the results of my current version is up to date, it did not update this writing.

  • Install a lower version of

In this case, there is a way to uninstall Pillow, and then re-install an older version of

pip uninstall Pillow	# 卸载当前pillow
pip uninstall PIL		# 可能还需要卸载这个模块
pip install Pillow==版本号		# 有些教程说6.1版本的可用

I have not practice for reference purposes only

  • Modify the module file

I made a bold operation, I took part in the import PILLOW_VERSION of functional.py to change the

from PIL import Image, ImageOps, ImageEnhance, __version__

Vision will be a warning to modify in Pycharm, verify that you can modify the

But only this is not enough, as used in the following procedure or PILLOW_VERSIONvariable, and then I made such an operation

PILLOW_VERSION=__version__

Note that this sentence should be placed before the statement PILLOW_VERSION all variables used, I was put in the sentence immediately following the import operation after all

In summary, my problem was resolved

Published 102 original articles · won praise 68 · views 5091

Guess you like

Origin blog.csdn.net/BBJG_001/article/details/104369234