[英]cannot import name 'parse_version' from 'sklearn.utils.fixes'
I am having serious problems with sklearn.我在使用 sklearn 时遇到了严重的问题。 In particular, when doing:
特别是,在执行以下操作时:
from sklearn.linear_model import LinearRegression
I get the following error:我收到以下错误:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-8-a35af2a4e137> in <module>
----> 1 from sklearn.linear_model import LinearRegression
~/anaconda3/lib/python3.7/site-packages/sklearn/__init__.py in <module>
78 from . import _distributor_init # noqa: F401
79 from . import __check_build # noqa: F401
---> 80 from .base import clone
81 from .utils._show_versions import show_versions
82
~/anaconda3/lib/python3.7/site-packages/sklearn/base.py in <module>
19 from . import __version__
20 from ._config import get_config
---> 21 from .utils import _IS_32BIT
22 from .utils.validation import check_X_y
23 from .utils.validation import check_array
~/anaconda3/lib/python3.7/site-packages/sklearn/utils/__init__.py in <module>
21
22 from .murmurhash import murmurhash3_32
---> 23 from .class_weight import compute_class_weight, compute_sample_weight
24 from . import _joblib
25 from ..exceptions import DataConversionWarning
~/anaconda3/lib/python3.7/site-packages/sklearn/utils/class_weight.py in <module>
5 import numpy as np
6
----> 7 from .validation import _deprecate_positional_args
8
9
~/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py in <module>
23 from contextlib import suppress
24
---> 25 from .fixes import _object_dtype_isnan, parse_version
26 from .. import get_config as _get_config
27 from ..exceptions import NonBLASDotWarning, PositiveSpectrumWarning
ImportError: cannot import name 'parse_version' from 'sklearn.utils.fixes' (/Users/federiconutarelli/anaconda3/lib/python3.7/site-packages/sklearn/utils/fixes.py)
which I am not able to fix since in fixes.py I can see我无法修复,因为在 fixes.py 中我可以看到
def _parse_version(version_string):
version = []
for x in version_string.split('.'):
try:
version.append(int(x))
except ValueError:
# x may be of the form dev-1ea1592
version.append(x)
return tuple(version)
which seem to me the same as parse_version.在我看来和 parse_version 一样。 Why Is this error occurring?
为什么会出现此错误? Can anyone please help me?
谁能帮帮我吗?
Thank you all,谢谢你们,
Federico费德里科
You may resolve this by creating a fresh conda environment.您可以通过创建新的 conda 环境来解决此问题。 Sometimes some conflicts prevent packages from running correctly.
有时,某些冲突会阻止软件包正确运行。
For my situation, I uninstall the two packages scipy
and scikit-learn
and then installed them.对于我的情况,我卸载了
scipy
和scikit-learn
这两个包,然后安装。 And then it works well.然后效果很好。 I try both
conda install
and pip install
for many times, so I can't tell which way to install is better. conda
conda install
和pip install
都试了很多次,分不清哪种安装方式更好。
In the detailed error report, there should be some lines relevant to scipy
.在详细的错误报告中,应该有一些与
scipy
相关的行。 So I think this is an error about the incompatibility between these two packages and therefore some dll doesn't work well.所以我认为这是关于这两个包之间不兼容的错误,因此一些 dll 不能正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.