为什么我不能将 sklearn 导入到我的 python 项目中?

问题描述 投票:0回答:0

我想使用

sklearn.neighbors
,但每当我尝试导入
sklearn
sklearn.neighbors
时,我都会收到相同的错误消息。

我正在使用以下版本:

Windows: 10.0.19044
Python: 3.7.3
Scikit-learn: 1.0.2
Numpy: 1.21.6
Scipy: 1.7.3

我不知道这是否相关:我正在尝试将其导入 FreeCAD 0.20.1.

有问题的错误信息:

>>> import sklearn
Traceback (most recent call last):
  File "C:\RoboDK\Python37\Lib\site-packages\sklearn\__check_build\__init__.py", line 48, in <module>
    from ._check_build import check_build  # noqa
  File "C:\Program Files\FreeCAD 0.20\bin\Lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
    return original_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'sklearn.__check_build._check_build'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\FreeCAD 0.20\bin\Lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
    return original_import(name, *args, **kwargs)
  File "C:\RoboDK\Python37\Lib\site-packages\sklearn\__init__.py", line 81, in <module>
    from . import __check_build  # noqa: F401
  File "C:\Program Files\FreeCAD 0.20\bin\Lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
    return original_import(name, *args, **kwargs)
  File "C:\RoboDK\Python37\Lib\site-packages\sklearn\__check_build\__init__.py", line 50, in <module>
    raise_build_error(e)
  File "C:\RoboDK\Python37\Lib\site-packages\sklearn\__check_build\__init__.py", line 31, in raise_build_error
    raise ImportError(
ImportError: No module named 'sklearn.__check_build._check_build'
___________________________________________________________________________
Contents of C:\RoboDK\Python37\Lib\site-packages\sklearn\__check_build:
setup.py                  _check_build.cp37-win_amd64.pyd__init__.py
__pycache__
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.

在多次尝试卸载、重新安装和搜索解决方案后,无论是否使用管理员访问权限,我仍然会收到相同的错误消息。我也尝试过旧版本的 scikit-learn,但没有任何运气。

我用

pip install -U scikit-learn
安装包。

我还检查了推荐的命令:

python -m pip show scikit-learn  # to see which version and where scikit-learn is installed
python -m pip freeze  # to see all packages installed in the active virtualenv
python -c "import sklearn; sklearn.show_versions()"

所有这些都将 scikit-learn 的安装版本列为 1.0.2,所以我想它工作正常。

python scikit-learn python-import
© www.soinside.com 2019 - 2024. All rights reserved.