Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 288
Taha Abdelhalim Nakabi Avatar asked Dec 26 '16 15:12

Taha Abdelhalim Nakabi


4 Answers

This line points to scipy.

from scipy.sparse.linalg import lsqr as sparse_lsqr

You can try:

pip uninstall scipy

pip install scipy

enjoy!

like image 192
chaggy Avatar answered Nov 07 '22 01:11

chaggy


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

like image 36
amiref Avatar answered Nov 07 '22 00:11

amiref


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.

like image 38
Joseph Lemien Avatar answered Nov 07 '22 01:11

Joseph Lemien


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.

like image 30
Markus Appel Avatar answered Nov 07 '22 00:11

Markus Appel