ImportError: cannot import name signature

故事扮演 提交于 2020-02-24 05:17:25

问题


I am tying to modify the original sklearn.CalibrationCV to create my won version. The original code has "from .utils.fixes import signature". So I did the following in my version:

from sklearn.utils.fixes import signature

but got a error:

ImportError: cannot import name signature

When check the sklearn source code on GitHub. I see the following code inside fixes.py:

try:
    from inspect import signature
except ImportError:
    from ..externals.funcsigs import signature

Then I did from inspect import signature directly. Still get "ImportError: cannot import name signature"

Besides how to fix this, I am also curious about why the original version can import a module that will be imported from another source? Thanks.


回答1:


  • In python 2, the inspect module does not have a signature method.
  • In python 3, the inspect module does have a signature method.

This code is just trying to work with both python 2 and 3.

You may want to use the funcsigs module if you are using python 2, or use sklearn.externals.funcsigs directly (for version sklearn >= 0.17).



来源:https://stackoverflow.com/questions/34457398/importerror-cannot-import-name-signature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!