11

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: The specified module could not be found

  • You should consider editing your post for clarity of intent and presentation; as it stands, it looks so clumsy to get the due attention. – nyedidikeke Dec 26 '16 at 15:06

8 Answers8

27

This line points to scipy.

from scipy.sparse.linalg import lsqr as sparse_lsqr

You can try:

pip uninstall scipy

pip install scipy

enjoy!

chaggy
  • 1,091
  • 1
  • 10
  • 18
  • I tried two or three methods as mentioned in the other answers. This worked. It is short and simple – SKT Apr 27 '20 at 13:31
4

Reinstallation of scipy, numpy, and scikit-learn packages fixed the error in my case.

amiref
  • 3,181
  • 7
  • 38
  • 62
3

You should open up "C:\Python27\lib\site-packages\sklearn\utils\fixes.py", and edit the contents. 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".

Second, replace the line if np_version < (1, 12, 0): with if np_version < (1, 12):.

More background info and detail available here, in a great answer from user DSM.

Community
  • 1
  • 1
Joseph
  • 138
  • 12
1

Install this numpy library instead of the one you use:

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

I assume you have Intel Math Kernal Libary installed.

Markus Appel
  • 3,138
  • 1
  • 17
  • 46
  • This approach worked for me. I first uninstalled numpy using `pip uninstall numpy` and then I downloaded and installed the version of `numpy` from the link posted by @Markus Appel. – edesz Mar 06 '19 at 19:56
0

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

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
}
Marco Ottina
  • 399
  • 5
  • 12
0

For me uninstalling scipy in conda env and then reinstalling using pip works.

Uninstall: conda remove --force scipy

Install: pip install scipy

dspencer
  • 4,297
  • 4
  • 22
  • 43
0

DLL missing can happen by a wide range of reasons. In your case it seems there is a mismatch between sklearn and its dependencies(Maybe different 32bit or 64bit installation of packages.). 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

Version: 0.23.1

Summary: A set of python modules for machine learning and data mining

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

Author: None

Author-email: None

License: new BSD

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

Requires: 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.

Sajad.sni
  • 187
  • 4
  • 15
0

pip install --user --upgrade numpy

pip install --user --upgrade scipy

pip install --user --upgrade matplotlib

pip install --user --upgrade scikit-learn

Coollook
  • 1
  • 1
  • 1
    Welcome to Stack Overflow! While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Feb 13 '23 at 20:47