我正在尝试为scikit-image提交PR,但我得到了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
我认为这可能是一个循环导入错误,但我不知道如何解决这个问题。我已经included frangi_filter
和hessian_filter
进入了过滤器的模块__init__.py
。
我还尝试了relative导入,resulted导致了相同的错误。
如何正确导入,以便解决循环导入问题?
答案 0 :(得分:6)
解决这个问题的一个丑陋的黑客方法是将该导入移到函数内部,例如
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
您可能想要创建单独的&#34;代理&#34; hessian_matrix
和hessian_matrix_eigvals
的函数不会使用导入污染每个函数。