问题
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
signaturemethod. - In python 3, the inspect module does have a
signaturemethod.
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