【解决】AttributeError: module ‘scipy.misc‘ has no attribute ‘toimage‘

末蓝、 2024-04-01 09:46 36阅读 0赞

问题:

使用 scipy.misc 模块时报错: AttributeError: module ‘scipy.misc’ has no attribute ‘toimage’,报错信息如下:

d048bd762453422d9cd7a810b0fb63e3.png

原因分析:

scipy.misc.toimage() 方法在 Scipy 1.0.0 版本中被弃用了,在 Scipy 1.3.0 版本中被完全删除了。

我使用的是 scipy 1.9.1 版本,所以报错

04b34d1a70494dc695b48baf908bfbb9.png

解决办法:

1、将 scipy 降为 1.0.0 版本

使用以下命令:

  1. conda uninstall scipy
  2. conda install scipy=1.0.0

但是 scipy 1.0.0 版本对 python 版本有要求,可能会安装失败,不推荐使用此办法。

2、使用 PIL 库 Image 模块中的 fromarray() 方法

首先导入相应的包

  1. from PIL import Image

然后将报错处的代码修改为以下代码:

  1. img = Image.fromarray(img)

d9b7c94706c547a5aec9efb6e0e4f32f.png

参考链接: python - AttributeError: module ‘scipy.misc’ has no attribute ‘toimage’ - Stack Overflow

发表评论

表情:
评论列表 (有 0 条评论,36人围观)

还没有评论,来说两句吧...

相关阅读