python - 将图像导入 python :cannot import name 'imread'

标签 python

我是 python 的新手,我想导入图像。

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)

但我遇到以下错误:无法导入名称“imread” 我已经成功安装了 numpy 和 scipy。

最佳答案

您还需要安装 PIL (Pillow),因为 scipy 使用它来读取图像:

pip install Pillow

注意 from the docs :

imread uses the Python Imaging Library (PIL) to read an image. The following notes are from the PIL documentation.

但是,您可能需要考虑切换到 scipy.imageio.imread,因为 scipy.misc.imreaddeprecated :

imread is deprecated! imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use imageio.imread instead

关于python - 将图像导入 python :cannot import name 'imread' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48923151/

相关文章:

python - 区间内自然数之和

python - 我可以对 df.column 的元素进行分类并创建一个不带迭代输出的列(Python-Pandas-Np)吗?

python - 我想用python制作gui来显示RDS MySQL DB中的表

python - 访问 url 时 Python 中的 SSLError( '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)' ),))

python - 如何在 MXnet 中使用多输入数据预测或训练网络?

python - 跨蓝图使用 url_for

python - 从文本到字典,更新键值

python - 跟踪 Joblib 中并行 for 循环的索引

python - 无法退出正在运行的 python 脚本

python - 如何使用 Gensim 加载 Word2vec 而不会出现 AttributeError?