ImportError: No module named filters

ImportError: No module named filters

我在 ubuntu 终端中使用以下命令安装了 skimage:

sudo apt-get install python-skimage

它安装成功,但在我的代码中使用它时 (from skimage.filters import threshold_local)。我得到一个错误:

Traceback (most recent call last):
  File "scan.py", line 4, in <module>
    from skimage.filters import threshold_local
ImportError: No module named filters

好心人帮我更正一下!

问题现已解决:D。我发现在 skimage '0.10.1' 中没有名为 'filters' 的模块,因为它有 'filter'。所以,当我使用命令

升级它时

sudo pip install --upgrade scikit-image

到版本'0.13.1',它带有'过滤器'模块而不是'filter'。 'filters' 模块具有阈值的所有属性,包括 'local' 和其他。

所以我在 Spyder 中遇到了同样的问题,Python 3.6.6.

这段代码(img 是一个 np 数组):

import skimage
val = skimage.filters.threshold_otsu(img)

给出:模块'skimage'没有属性'filters'

我尝试了 pip install --upgrade scikit-image 但没有任何变化。 Skimage 确实在我的系统路径中: *'C:\WPy-3661\python-3.6.6.amd64\lib\site-packages',过滤器文件夹与 init 文件位于其中。

但如果我这样做:

from skimage import filters as anything
val = skimage.filters.threshold_otsu(img)

然后就可以了。这不正常吧?

请注意,在我的 sys.path 路径中只有一个 skimage 文件夹。所以我不认为这是一个重复的问题。

我也有同样的问题,但下面的代码帮助了我:

!sudo apt-get install python-skimage
from skimage.filters import  roberts, prewitt, sobel, scharr, laplace