I'm new to python and I want to import an image.
import numpy as np
from scipy.misc import imread, imsave, imresize
# Read an JPEG image into a numpy array
img = imread('Cover.jpg')
print(img.dtype, img.shape)
but I face with following error: cannot import name 'imread'
I've already successfully installed numpy and scipy.
You also need to install PIL (Pillow) as that is what scipy
uses to read images:
pip install Pillow
note from the docs:
imread uses the Python Imaging Library (PIL) to read an image. The following notes are from the PIL documentation.
however, you might want to think about switching to scipy.imageio.imread
since scipy.misc.imread
is deprecated :
imread is deprecated! imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use imageio.imread instead
Use:
from imageio import imread
it worked for me.
Apparently a lot of people had this issue and the solution was to install Pillow
. Perhaps try to install Pillow and run it again
sudo pip install Pillow==2.6.0
Source of information: https://github.com/Newmu/stylize/issues/1
First, you should have Pillow, later your scipy version should be lower than 1.1.0
pip install Pillow
pip install scipy==1.1.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With