NameError: name ‘Image‘ is not defined

Pycharm 报错“NameError: name ’ Image’is not defined”

##When running the code today, the following error occurred:
insert image description here
insert image description here
According to the search, it can be installed directly on the anaconda prompt:

pip install Pillow
 pip insall image

Or search directly in pycharm
insert image description here
insert image description here
, but I can search for pillow, but not for image. And pip install image reports an error:

**Bold Text** __Bold Text__
Notice! ! ! Turn off the VPN! ! ! Install again! !

pip install Pillow from PIL import Image

insert image description here
###Some bloggers provided the following methods: But I tried them all, but the result was not satisfactory, and I still reported an error! !

Douban Mirror Site

pip install Pillow from PIL import Image -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com 

Tsinghua University:

pip install Pillow from PIL import Image -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn 

Douban:

pip install   Pillow from PIL import Image -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

insert image description here
at last! ! ! The input pip install imagewas successful!

insert image description herebut! I opened Pycharm again and still reported an error, still:
insert image description here
I found a very magical thing at this time, the library displayed in Pycharm and Anaconda is actually different, the image library exists in Anaconda, but does not exist in Pycharm! Look at the picture:
insert image description here
I went back to see the import statement and found:

from PIL import Image as pil_image

So
insert image description here
change to:
insert image description here
Finally you're done, and it took a long time to go around, hey!

Guess you like

Origin blog.csdn.net/qq_43306047/article/details/127773383
Recommended