Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble with relative / absolute functions import in scikit-image

I'm trying to submit a PR for scikit-image, but I get a Travis-CI error:

  Traceback (most recent call last):
  File "doc/examples/edges/plot_canny.py", line 22, in <module>
    from skimage import feature
  File "/home/travis/build/scikit-image/scikit-image/skimage/feature/__init__.py", line 9, in <module>
    from .peak import peak_local_max
  File "/home/travis/build/scikit-image/scikit-image/skimage/feature/peak.py", line 3, in <module>
    from ..filters import rank_order
  File "/home/travis/build/scikit-image/scikit-image/skimage/filters/__init__.py", line 11, in <module>
    from ._frangi import frangi_filter, hessian_filter
  File "/home/travis/build/scikit-image/scikit-image/skimage/filters/_frangi.py", line 2, in <module>
    from skimage.feature import hessian_matrix, hessian_matrix_eigvals
ImportError: cannot import name hessian_matrix

I suppose that this might be a circular import error, but I don't quite get how to resolve the issue. I've already included frangi_filter and hessian_filter into filter's module __init__.py.

I've also tried relative import, which resulted into the same errors.

How can I do a proper import, so the circular import issue can be resolved?

like image 230
beyondfloatingpoint Avatar asked Jun 13 '16 03:06

beyondfloatingpoint


1 Answers

One ugly hack to resolve this would be to move that import inside the function, like

def hessian_filter(image, scale=(1, 10), scale_ratio=2, beta1=0.5, beta2=15):
    """
       Blah-blah-blah
    """
    from ..feature import hessian_matrix, hessian_matrix_eigvals
    # function body

You might want to create separate "proxy" functions for hessian_matrix and hessian_matrix_eigvals to not pollute every function with imports.

like image 64
Artem Sobolev Avatar answered Nov 06 '22 00:11

Artem Sobolev