无法导入scipy.misc.imread

时间:2012-02-15 17:58:17

标签: python scipy

我之前和其他人见过这个问题,但还没有找到解决办法。

我所要做的就是:

from scipy.misc import imread

我得到了

/home1/users/joe.borg/<ipython-input-2-f9d3d927b58f> in <module>()
----> 1 from scipy.misc import imread

/software/Python/272/lib/python2.7/site-packages/scipy/misc/__init__.py in <module>()
     16 try:
     17     from pilutil import *
---> 18     __all__ += pilutil.__all__
     19 except ImportError:
     20     pass

NameError: name 'pilutil' is not defined

但是当我自己from pilutil import *时没有导入错误就没问题了。甚至...... / site-packages / scipy / misc / pilutil.py存在,所以我不知道为什么会失败。

11 个答案:

答案 0 :(得分:54)

您可能需要安装PILPillow

答案 1 :(得分:5)

text中的方法 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if let cell = tableView.dequeueReusableCell(withIdentifier: ItemTableViewCell.identifier, for: indexPath) as? ItemTableViewCell{ cell.item = items[indexPath.row] cell.delegate = self cell.selectionStyle = .none return cell } return UITableViewCell() } 需要imread的分叉包名为scipy.misc。如果您在安装正确版本的PIL时遇到问题,请尝试在其他软件包中使用PIL

Pillow

要在不使用imread的情况下阅读from matplotlib.pyplot import imread im = imread(image.png) 张图片:

jpg

答案 2 :(得分:3)

你可以试试 from scipy.misc.pilutil import imread代替from scipy.misc import imread

请查看GitHub页面:https://github.com/amueller/mglearn/issues/2 了解更多详情。

答案 3 :(得分:3)

Scipy在v1.0中弃用了图像I / O功能:

imread在SciPy 1.0.0中已弃用,在1.2.0中将被删除。改用imageio.imread

使用imageio模块:

img = imageio.imread(fina)

可能存在一些差异。看到 https://imageio.readthedocs.io/en/stable/scipy.html

答案 4 :(得分:2)

扩展Naeem的answer

如果要使用高于1.3.0的scipy版本,则按照imread函数的scipy的documentation中的指示,我们可以改用imageio模块。

要以复制scipy的imread功能的方式成功使用imageio imread函数,可以按照here中所述的说明进行操作(免责声明:我尚未亲自尝试过

答案 5 :(得分:1)

查看说明文件scipy.misc.imread已过时。 它说要安装imageio,而改用imageio.imread。 很棒!

答案 6 :(得分:0)

我在尝试使用

时收到错误消息
from scipy.misc import imread

我能够删除错误并使用上述行,首先安装numpy+mkl,然后从Christoph Gohlke's website安装scipy

对我来说,这是:

pip install numpy-1.11.1+mkl-cp27-cp27m-win32.whl
pip install scipy-0.17.1-cp27-cp27m-win32.whl

您需要为您的系统选择正确的版本。

此外,请确保pip命令安装模块。如果您已经安装了其中一个或多个,则可能需要使用pip强制重新安装。

答案 7 :(得分:0)

pip3 install Pillow==4.3.0对我有好处,但Pillow==5.1.0提出错误。所以你可能只需更换枕头版本。

答案 8 :(得分:0)

如果您的枕头安装了scipy,但仍给您错误,请检查您的scipy版本,因为自1.3.0rc1起已将其从scipy中删除。

而是安装scipy == 1.1.0。它为我工作!

检查https://github.com/scipy/scipy/issues/6212

答案 9 :(得分:0)

您可以使用 Transact-SQL article 答案。

在较新版本的 scipy 中,imread 已被删除。 您可以改用 imageio.imread

import imageio
im = imageio.imread('example.png')

但是如果要使用scipy,则必须使用1.0或1.1版本。 为此,请使用以下命令。

conda install -c anaconda scipy==1.0

然后要使用“imread”,您需要安装Pillow。您可以使用以下命令安装pillow

pip install pillow

答案 10 :(得分:-1)

你必须像这样导入它

from scipy import misc

这样就可以正常工作了。