简体   繁体   English

尝试导入 sklearn 模块时出错:ImportError:DLL 加载失败:找不到指定的模块

[英]Error when trying to import sklearn modules : ImportError: DLL load failed: The specified module could not be found

I tried to do the following importations for a machine learning project:我尝试为机器学习项目执行以下导入:

from sklearn import preprocessing, cross_validation, svm
from sklearn.linear_model import LinearRegression

I got this error message:我收到此错误消息:

Traceback (most recent call last):
  File "C:/Users/Abdelhalim/PycharmProjects/ML/stock pricing.py", line 4, in <module>
    from sklearn import preprocessing, cross_validation, svm
  File "C:\Python27\lib\site-packages\sklearn\__init__.py", line 57, in <module>
    from .base import clone
  File "C:\Python27\lib\site-packages\sklearn\base.py", line 12, in <module>
    from .utils.fixes import signature
  File "C:\Python27\lib\site-packages\sklearn\utils\__init__.py", line 11, in <module>
    from .validation import (as_float_array,
  File "C:\Python27\lib\site-packages\sklearn\utils\validation.py", line 18, in <module>
    from ..utils.fixes import signature
  File "C:\Python27\lib\site-packages\sklearn\utils\fixes.py", line 291, in <module>
    from scipy.sparse.linalg import lsqr as sparse_lsqr
  File "C:\Python27\lib\site-packages\scipy\sparse\linalg\__init__.py", line 112, in <module>
    from .isolve import *
  File "C:\Python27\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
    from .iterative import *
  File "C:\Python27\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 7, in <module>
    from . import _iterative
ImportError: DLL load failed: The specified module could not be found.

Please help I tried everything but nothing worked.请帮助我尝试了一切,但没有任何效果。 I tried these solutions as well: ImportError: DLL load failed: Le module spécifié est introuvable我也尝试过这些解决方案: ImportError: DLL load failed: Le module spécifié est introuvable

ImportError: DLL load failed: The specified module could not be found 导入错误:DLL 加载失败:找不到指定的模块

This line points to scipy.这条线指向 scipy。

from scipy.sparse.linalg import lsqr as sparse_lsqr

You can try:你可以试试:

pip uninstall scipy

pip install scipy

enjoy!请享用!

You should open up "C:\\Python27\\lib\\site-packages\\sklearn\\utils\\fixes.py", and edit the contents.您应该打开“C:\\Python27\\lib\\site-packages\\sklearn\\utils\\fixes.py”,然后编辑内容。 There are two specific changes you should make:您应该进行两项具体更改:

First , copy-and-paste the contents of https://github.com/scikit-learn/scikit-learn/blob/74a9756fa784d1f22873ad23c8b4948c6e290108/sklearn/utils/fixes.py into the file "C:\\Python27\\lib\\site-packages\\sklearn\\utils\\fixes.py".首先,将https://github.com/scikit-learn/scikit-learn/blob/74a9756fa784d1f22873ad23c8b4948c6e290108/sklearn/utils/fixes.py的内容复制并粘贴到文件“C:\\Python27\\lib\\site-包\\sklearn\\utils\\fixes.py”。

Second , replace the line if np_version < (1, 12, 0): with if np_version < (1, 12): .其次,将 if np_version < (1, 12, 0):替换为if np_version < (1, 12):

More background info and detail available here , in a great answer from user DSM .此处提供更多背景信息和详细信息,来自用户DSM的精彩回答。

重新安装scipynumpyscikit-learn包修复了我的错误。

Install this numpy library instead of the one you use:安装这个 numpy 库而不是你使用的库:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

I assume you have Intel Math Kernal Libary installed.我假设您已经安装了 Intel Math Kernal Libary。

i've found a silly solution, similar to the @saggy ones: iteratively run the script from command line, if compare a "DLL error" look for a package/module/library/wattelapesca name, then pip uninstall thatPackage and re-install it我找到了一个愚蠢的解决方案,类似于@saggy 的解决方案:从命令行迭代运行脚本,如果比较“DLL 错误”,查找包/模块/库/wattelapesca 名称,然后pip uninstall thatPackage并重新安装它

as a pseudocode:作为伪代码:

notWorking = true
while( nonFunge ){
    run_the_script_from_command_line()
    output = get_last_cmd_output()
    if( "ImportError: DLL load failed: blabla" in output ){
        doomed_package = look_for_package_module_library_wattelapesca(output)
        exec("pip uninstall " + doomed_package )
        exec("pip install " + doomed_package )
    }else # all ok, the script works
         notWorking = false
}

For me uninstalling scipy in conda env and then reinstalling using pip works.对我来说,在 conda env 中卸载 scipy,然后使用 pip 重新安装。

Uninstall: conda remove --force scipy卸载: conda remove --force scipy

Install: pip install scipy安装: pip install scipy

DLL missing can happen by a wide range of reasons. DLL 丢失的原因有很多。 In your case it seems there is a mismatch between sklearn and its dependencies(Maybe different 32bit or 64bit installation of packages.).在您的情况下,sklearn 及其依赖项之间似乎不匹配(可能是不同的 32 位或 64 位安装包。)。 As different answers point out to different packages, a general way to find out dependencies is using:由于不同的答案指出不同的包,找出依赖关系的一般方法是使用:

pip show scikit-learn

and the output is:输出是:

Name: scikit-learn名称:scikit-learn

Version: 0.23.1版本:0.23.1

Summary: A set of python modules for machine learning and data mining总结:一套用于机器学习和数据挖掘的python模块

Home-page: http://scikit-learn.org主页: http : //scikit-learn.org

Author: None作者:无

Author-email: None作者邮箱:无

License: new BSD许可证:新 BSD

Location: c:\\users\\username\\appdata\\local\\programs\\python\\python37\\lib\\site- packages位置:c:\\users\\username\\appdata\\local\\programs\\python\\python37\\lib\\site-packages

Requires: joblib, numpy, threadpoolctl, scipy需要:joblib、numpy、threadpoolctl、scipy

So It's probable that the root problem returns to one of 'Requires' packages.因此,根本问题很可能会回到“需要”包之一。 By the way the error lines also can point out which package causes error.顺便说一句,错误行还可以指出哪个包导致错误。 Try reinstalling these packages should solve the problem.尝试重新安装这些软件包应该可以解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ImportError:DLL加载失败:找不到指定的模块。 尝试“从PIL导入图像”时 - ImportError: DLL load failed: The specified module could not be found. when trying to “from PIL import Image” 导入错误:DLL 加载失败:找不到指定的模块(sklearn) - ImportError: DLL load failed: The specified module could not be found (sklearn) Tensorflow 错误:ImportError: DLL 加载失败:找不到指定的模块 - Tensorflow Error: ImportError: DLL load failed: The specified module could not be found ver.2 PyGreSQL ERROR: from _pg import * ImportError: DLL load failed: The specified module could not be found - ver.2 PyGreSQL ERROR: from _pg import * ImportError: DLL load failed: The specified module could not be found 导入 pptx 时出错“导入错误:DLL 加载失败:找不到指定的过程。” - Error when Import pptx "ImportError: DLL load failed: The specified procedure could not be found." 执行对象检测时,“ ImportError:DLL加载失败:找不到指定的模块”出现此错误 - “ImportError: DLL load failed: The specified module could not be found” getting this error when doing object detection 导入 Dash 时出错:“ImportError: DLL load failed while importing _brotli: The specified module could not be found.” - Error when importing Dash: "ImportError: DLL load failed while importing _brotli: The specified module could not be found." 导入错误:DLL 加载失败。 指定的模块无法找到 - Import Error: DLL load failed. The specified module could not be found Pyinstaller:导入错误:DLL 加载失败:找不到指定的模块 - Pyinstaller: Import Error: DLL load failed: The specified module could not be found import pystan._api failed:ImportError: DLL load failed: 找不到指定的模块 - import pystan._api failed:ImportError: DLL load failed: The specified module could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM