NameError: name ‘Image‘ is not defined

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

##今天在运行代码时,出现了如下错误:
NameError: name ‘Image‘ is not defined
NameError: name ‘Image‘ is not defined
根据搜索,查到可以在anaconda prompt直接安装:

pip install Pillow
 pip insall image

或者直接在pycharm搜索
NameError: name ‘Image‘ is not defined
NameError: name ‘Image‘ is not defined
但是我的能搜索到pillow,搜索不到image。并且pip install image 报错:

**加粗文本** __加粗文本__
注意!!!关掉VPN!!! 再安装!!

pip install Pillow from PIL import Image

NameError: name ‘Image‘ is not defined
###有博主提供了如下方法:但是我都尝试了,结果并不如意,依然报错!!

豆瓣镜像网站

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

清华大学:

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

豆瓣:

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

NameError: name ‘Image‘ is not defined
最后!!!输入pip install image居然成功了!

NameError: name ‘Image‘ is not defined但是!我再打开Pycharm居然还是报错,依然是:
NameError: name ‘Image‘ is not defined
这时发现了一个很神奇的事情,Pycharm 跟 Anaconda中显示的库居然不一样,image库在Anaconda中存在,而在Pycharm 中不存在!看图:
NameError: name ‘Image‘ is not defined
我又返回去看import语句发现:

from PIL import Image as pil_image

所以要将
NameError: name ‘Image‘ is not defined
改为:
NameError: name ‘Image‘ is not defined
最终大功告成绕了一圈,花费了好长的时间,哎!

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
扎眼的阳光的头像扎眼的阳光普通用户
上一篇 2023年3月30日
下一篇 2023年3月30日

相关推荐