有一个不错的解决module xxx has no attribute的思路

今天看见一篇博客解决问题的思路给了我很大的启发,于是我就将他记录下来,大家可以一起学习一下,在文章的最后我也会挂出他的链接:
这里具体为具体错误:


module ‘keras.preprocessing.image‘ has no attribute ‘load_img‘


解决办法:
1.首先找到错误代码位置:
在这里插入图片描述
有一个不错的解决module xxx has no attribute的思路_第1张图片
他这里说‘’keras.preprocessing.image‘’没有"load_img"属性,于是按住ctrl点击前面的image,进入image.py,然后在image.py文件中查找load_img,发现有两个搜素结果
有一个不错的解决module xxx has no attribute的思路_第2张图片
有一个不错的解决module xxx has no attribute的思路_第3张图片
因为第二个load_img在注释里面,显然是没有作用的,故肯定是第一个load_img,然后观察他发现他现在被封装到image_utils里面去了,于是:
有一个不错的解决module xxx has no attribute的思路_第4张图片
这里的image应该改为image_utils:
有一个不错的解决module xxx has no attribute的思路_第5张图片
然后这里报红,这是因为没有导入那个image_utils包的原因,然后导入那个包:
有一个不错的解决module xxx has no attribute的思路_第6张图片
就会发现Demo.py文件没有报错,然后再运行,成功运行!
有一个不错的解决module xxx has no attribute的思路_第7张图片

所以一般遇见module xxx has no attribute很有可能是因为他的版本更新,里面的一些功能被封装到别的包里面去了,按照以上的办法应该能解决这个问题。

已解决module ‘keras.preprocessing.image‘ has no attribute ‘load_img‘

你可能感兴趣的:(Python学习,python)