Problem with relative / absolute import functions in scikit-image

I try to send a PR for a 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 this might be a circular import error, but I donโ€™t quite understand how to solve the problem. I already included frangi_filter and hessian_filter in the __init__.py filter module.

I also tried relative imports, which resulted in the same errors.

How can I make the correct import, so the problem with cyclic import can be solved?

+8
python scikit-image
source share
1 answer

One ugly hack to solve this issue is moving this import inside a function, e.g.

 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 so as not to pollute each function with imports.

+6
source share

All Articles