機略戦記

Maneuver warfare

scipy.miscにimreadが無いと言われる問題

結論

Pillow ( Pillow: the friendly PIL fork )をインストールすれば治る。

pipを使ってるならこう:

$ pip install Pillow

症状

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-f982853d0813> in <module>()
     58     import matplotlib.pyplot as plt
     59     import scipy.misc
---> 60     main()

<ipython-input-6-f982853d0813> in main()
     46 
     47 def main():
---> 48     img = scipy.misc.imread('donkey.png')[:, :, :3]
     49     trimap = scipy.misc.imread('donkeyTrimap.png')[:, :, :3]
     50     alpha = knn_matte(img, trimap)

AttributeError: module 'scipy.misc' has no attribute 'imread'

no attributeと言われる。

原因

Miscellaneous routines (scipy.misc) — SciPy v0.19.1 Reference Guide

Note that Pillow (https://python-pillow.org/) is not a dependency of SciPy, but the image manipulation functions indicated in the list below are not available without it.

との事です。