天天看点

遇到问题: Python报错module 'scipy.misc' has no attribute 'imsave'

https://blog.csdn.net/u013318356/article/details/95340391

方法1 有的帖子说 需要安装 pillow  然后我pip install pillow 依然没有用 还是报错

方法2 有的帖子说 需要安装moviepy 以及pillow 然后我pip install moviepy 依然没有用 还是报错

测试验证: 新建一个.py文件:

import scipy.misc

print(dir(scipy.misc))

可以看到 如果显示的这个路径里面你 没有imread 或者imsave 一定依然在程序里面会报错

方法3 亲试有效

如果不想改程序 ,建议pip uninstall scipy,

我尝试了pip install scipy==1.2.0,
遇到问题: Python报错module 'scipy.misc' has no attribute 'imsave'

但是有imread imsave,奇怪???

下图是报错结果,建议使用

imageio.imwrite

遇到问题: Python报错module 'scipy.misc' has no attribute 'imsave'

解决方法:

1 尝试使用imageio.write

2 尝试安装scipy1.0.0

我尝试使用 imageio.write之后

遇到问题: Python报错module 'scipy.misc' has no attribute 'imsave'
发现如下报错:
遇到问题: Python报错module 'scipy.misc' has no attribute 'imsave'

Lossy conversion from float32 to uint8. Range [0, 1].

Convert image to uint8 prior to saving to suppress this warning.

从float32到uint8的有损转换,区间[0,1]。

在保存之前将图像转换为uint8来抑制这个警告。

也就是说图像有损,不清晰,确实是这样,

难道是因为使用指令imageio.write的原因

遇到问题: Python报错module 'scipy.misc' has no attribute 'imsave'

then,参考此文章:http://www.it1352.com/899106.html

下面参考了EGNet的写法

res = res.sigmoid().data.cpu().numpy().squeeze()
# misc.imsave(save_path + name + '.png', res)
res = 255 * res
print('=>res2', res)
res = res.astype(np.uint8)
print('=>res3', res)
cv2.imwrite(save_path + name + '.png', res)
# imageio.imwrite(save_path + name + '.png', res)
           

方法4 (还未尝试)我认为此方法等同于方法3

如果不想改程序 ,建议pip uninstall scipy,

然后到https://pypi.org/project/scipy/1.2.0/#files 下载scipy1.2.0 手动安装

自动安装会自动安装最新版 1.3.0的scipy,他 没有imsave 没有imread

重新安装完了之后,问题解决 程序不报错

遇到问题: Python报错module 'scipy.misc' has no attribute 'imsave'