安装后无法导入scikitlearn

2024-09-27 00:21:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在python中使用scikit-learn库,但是我完全无法将它导入到我的python项目中。我在网上找到的所有东西我都关注过,但我几乎不知道如何解决这个问题

我创建了一个新的python环境,并尝试简单地使用pip install scipypip install scikit-learn,但无法成功导入scipy或scikit学习。使用windows binaries,我能够使scipy正常工作,但是scikit-learn二进制文件继续给我一个错误。错误如下所示:

>>> import sklearn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\sklearn\__init__.py", line 76, in <module>
    from .base import clone
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\sklearn\base.py", line 16, in <module>
    from .utils import _IS_32BIT
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\sklearn\utils\__init__.py", line 20, in <module>
    from .validation import (as_float_array,
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\sklearn\utils\validation.py", line 21, in <module>
    from .fixes import _object_dtype_isnan
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\sklearn\utils\fixes.py", line 18, in <module>
    from scipy.sparse.linalg import lsqr as sparse_lsqr  # noqa
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\scipy\sparse\linalg\__init__.py", line 113, in <module>
    from .isolve import *
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
    from .iterative import *
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 10, in <module>
    from . import _iterative
ImportError: DLL load failed: The specified module could not be found.

scikit-learn binaries之上,它表示需要numpy+mlk模块。我尝试卸载numpy并用pip重新安装numpy+mlk二进制文件,但是一旦我这样做,我甚至无法导入numpy。它会给我一个带有链接的长错误消息:

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.7 from "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\Scripts\python.exe"
  * The NumPy version is: "1.19.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed: The specified module could not be found.

我似乎也无法解决这个问题。。。网站上给出的大多数故障排除策略都不适用于我,那些适用于我的策略也没有帮助。我正在Windows10中使用Python 3.7.9。非常感谢


Tags: infrompyimportlibpackageslinesite
1条回答
网友
1楼 · 发布于 2024-09-27 00:21:23

明白了@yoyoyo通过建议conda环境帮助了我。Conda附带了scipyscikit-learnscikit-image都是预安装的。使用conda安装和导入任何我需要的模块都不会让人头疼

相关问题 更多 >

    热门问题