无法导入sklearn([WinError 126]找不到指定的模块)

时间:2020-06-28 15:46:59

标签: python pytorch

from sklearn import datasets

我无法导入sklearn

这是错误:

OSError                                   Traceback (most recent call last)

<ipython-input-13-f9e6334b9a20> in <module>
  1 import torch
  2 import numpy as np
   ----> 3 from sklearn import datasets
  4 
  5 X_numpy, y_numpy = datasets.make_regression(n_samples=100, n_features=1, noise=20, 
  random_state=1)

 c:\users\kadiem alqazzaz\appdata\local\programs\python\python37\lib\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 

c:\users\kadiem alqazzaz\appdata\local\programs\python\python37\lib\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

c:\users\kadiem alqazzaz\appdata\local\programs\python\python37\lib\site-packages\sklearn\utils\__init__.py in <module>
 18 import warnings
 19 import numpy as np
---> 20 from scipy.sparse import issparse
 21 
 22 from .murmurhash import murmurhash3_32

c:\users\kadiem alqazzaz\appdata\local\programs\python\python37\lib\site-packages\scipy\__init__.py in <module>
102 
103 # Allow distributors to run custom init code
--> 104 from . import _distributor_init
105 
106 __all__ += _num.__all__

c:\users\kadiem alqazzaz\appdata\local\programs\python\python37\lib\site-packages\scipy\_distributor_init.py in <module>
 59             os.chdir(libs_path)
 60             for filename in glob.glob(os.path.join(libs_path, '*dll')):
 ---> 61                 WinDLL(os.path.abspath(filename))
 62         finally:
 63             os.chdir(owd)

 c:\users\kadiem alqazzaz\appdata\local\programs\python\python37\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
362 
363         if handle is None:
--> 364             self._handle = _dlopen(self._name, mode)
365         else:
366             self._handle = handle

OSError: [WinError 126] The specified module could not be found

当我输入pip install sklearn时,我已经满足要求:

Requirement already satisfied: sklearn in c:\users\kadiem alqazzaz\appdata\local\programs\python\python37\lib\site-packages (0.0) Requirement already satisfied: scikit-learn in c:\users\kadiem alqazzaz\appdata\local\programs\python\python37\lib\site-packages (from sklearn) (0.23.1) Requirement already satisfied: joblib>=0.11 in c:\users\kadiem alqazzaz\appdata\local\programs\python\python37\lib\site-packages (from scikit-learn->sklearn) (0.15.1) Requirement already satisfied: threadpoolctl>=2.0.0 in c:\users\kadiem alqazzaz\appdata\local\programs\python\python37\lib\site-packages (from scikit-learn->sklearn) (2.1.0) Requirement already satisfied: numpy>=1.13.3 in c:\users\kadiem alqazzaz\appdata\local\programs\python\python37\lib\site-packages (from scikit-learn->sklearn) (1.18.5) Requirement already satisfied: scipy>=0.19.1 in c:\users\kadiem alqazzaz\appdata\local\programs\python\python37\lib\site-packages (from scikit-learn->sklearn) (1.5.0)

所以我为什么不能使用sklearn,谢谢您的帮助。

编辑:当我在cmd中导入sklearn时没有任何问题,但是,当我使用Jupyter Notebook运行时,出现上述错误。

2 个答案:

答案 0 :(得分:1)

只需确保库搜索路径中的OpenSlide DLL

否则: 下载OpenSlide Windows二进制文件,然后需要将“ bin”文件夹添加到您的环境路径中

答案 1 :(得分:0)

通常,当您的计算机上有多个版本的Python时,就会发生这种情况。

尝试通过以下方式安装sklearn

python -m pip install sklearn

如果这将安装新的sklearn,则意味着您的pippython具有不同的路径,而pip仅为您安装的另一个Python版本安装了sklearn在您的系统中。