【解决】AttributeError: module ‘scipy.misc‘ has no attribute ‘toimage‘
问题:
使用 scipy.misc 模块时报错: AttributeError: module ‘scipy.misc’ has no attribute ‘toimage’,报错信息如下:
原因分析:
scipy.misc.toimage() 方法在 Scipy 1.0.0 版本中被弃用了,在 Scipy 1.3.0 版本中被完全删除了。
我使用的是 scipy 1.9.1 版本,所以报错
解决办法:
1、将 scipy 降为 1.0.0 版本
使用以下命令:
conda uninstall scipy
conda install scipy=1.0.0
但是 scipy 1.0.0 版本对 python 版本有要求,可能会安装失败,不推荐使用此办法。
2、使用 PIL 库 Image 模块中的 fromarray() 方法
首先导入相应的包
from PIL import Image
然后将报错处的代码修改为以下代码:
img = Image.fromarray(img)
参考链接: python - AttributeError: module ‘scipy.misc’ has no attribute ‘toimage’ - Stack Overflow
还没有评论,来说两句吧...