ImportError: cannot import name 'imread' from 'scipy.misc'
Fixes ImportError: cannot import name 'imread' from 'scipy.misc' Use when old code/tutorials doing `from scipy.misc import imread` on scipy>=1.3 Not for: you just need any image reader (use imageio or PIL directly)
How to fix ImportError: cannot import name 'imread' from 'scipy.misc'
scipy removed imread/imresize/imsave in 1.3. Replace from scipy.misc import imread with imageio (from imageio import imread) or PIL (Image.open(path)). imageio is scipy's own recommended replacement and returns the same numpy array.
The exact error
ImportError: cannot import name 'imread' from 'scipy.misc'Fix it
python -m pip install imageio
Expected: installed
- Replace
from scipy.misc import imreadwithfrom imageio import imread.
Expected: same numpy array back
- For imresize: use
Image.fromarray(arr).resize((w, h))from PIL.
Expected: equivalent resize
When this applies
old code/tutorials doing from scipy.misc import imread on scipy>=1.3
When this does NOT apply
you just need any image reader (use imageio or PIL directly)
Versions
scipy >= 1.3
Why it happens
scipy dropped its PIL wrappers; imageio became the blessed replacement.
Edge cases
imageio v3 changed the API slightly; imageio.v2.imread keeps the old behavior.