I’m trying to call a function from the cluster module, like so:
import sklearn db = sklearn.cluster.DBSCAN()
and I get the following error:
AttributeError: 'module' object has no attribute 'cluster'
Tab-completing in IPython, I seem to have access to the base, clone, externals, re, setup_module, sys, and warning modules. Nothing else, though others (including cluster) are in the sklearn directory.
Following pbu’s advice below and using
from sklearn import cluster
I get:
Traceback (most recent call last):
File "test.py", line 2, in <module>
from sklearn import cluster
File "C:Python34libsite-packagessklearncluster__init__.py", line 6, in <module>
from .spectral import spectral_clustering, SpectralClustering
File "C:Python34libsite-packagessklearnclusterspectral.py", line 13, in <module>
from ..utils import check_random_state, as_float_array
File "C:Python34libsite-packagessklearnutils__init__.py", line 16, in <module>
from .class_weight import compute_class_weight, compute_sample_weight
File "C:Python34libsite-packagessklearnutilsclass_weight.py", line 7, in <module>
from ..utils.fixes import in1d
File "C:Python34libsite-packagessklearnutilsfixes.py", line 318, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "C:Python34libsite-packagesscipysparselinalg__init__.py", line 109, in <module>
from .isolve import *
File "C:Python34libsite-packagesscipysparselinalgisolve__init__.py", line 6, in <module>
from .iterative import *
File "C:Python34libsite-packagesscipysparselinalgisolveiterative.py", line 7, in <module>
from . import _iterative
ImportError: DLL load failed: The specified module could not be found.
I’m using Python 3.4 on Windows, scikit-learn 0.16.1.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You probably don’t use Numpy+MKL, but only Numpy.
I had the same problem and reinstalling Numpy with MKL
pip install --upgrade --force-reinstall "numpy‑1.16.3+mkl‑cp37‑cp37m‑win32.whl"
fixed it.
Note: update the file to the latest version, possibly 64bit – see the list of available Windows binaries
Method 2
Problem was with scipy/numpy install. I’d been using the (normally excellent!) unofficial installers from http://www.lfd.uci.edu/~gohlke/pythonlibs/. Uninstall/re-install from there made no difference, but installing with the official installers (linked from http://www.scipy.org/install.html) did the trick.
Method 3
I am using anaconda got the same error as the OP, when loading Orange, or PlotNine.
I can’t recall when this start to happen.
Tracing the dependency of Anaconda3Libsite-packagesscipyspecial_ufuncs.cp36-win32.pyd, libifcoremd.dll and libmmd.dll are missing in DependencyWalk. Searching them in anaconda root directry, they are located in both ICC_RT and one version of MKL package.
Adding Anaconda3pkgsmkl-2017.0.3-0Librarybin to PATH, seems to fix SciPy and NumPy related DLL load failure, the above package starts to work again.
I still don’t know how to fix this properly. Apparently the downside is that the MKL package could be updated and versions may change so does the path. In this aspect Its equally inconvenient as adding a non-managed package.
Reinstalling ICC_RT fixed the issue for me, libmmd.dll and the related dlls are automatically copied into anaconda3/library/bin afterwards, which is automatically added into PATH by activate command. All previous numpy/scipy related cant load DLL errors are gone now.
Method 4
From the error log, it shows that scipy module is the most recent module fails to import
File "C:Python34libsite-packagessklearnutilsfixes.py", line 318, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "C:Python34libsite-packagesscipysparselinalg__init__.py", line 109, in <module>
from .isolve import *
File "C:Python34libsite-packagesscipysparselinalgisolve__init__.py", line 6, in <module>
from .iterative import *
File "C:Python34libsite-packagesscipysparselinalgisolveiterative.py", line 7, in <module>
from . import _iterative
ImportError: DLL load failed: The specified module could not be found.
I have the same error that show the same log, the problem’d gone when I uninstall/install scipy:
pip uninstall scipy pip install scipy
Method 5
Place this line on top of the python file
from sklearn import cluster
That should do it :))
Method 6
For me what fixed it were these commands:
pip uninstall sklearn pip uninstall scikit-learn pip uninstall scipy pip install scipy pip install scikit-learnhere
Method 7
I had the same issue and solved it by installing/updating the mkl package:
conda install mkl
or
pip install mkl
Just for full information, this also downgraded the following packages:
The following packages will be UPDATED:
mkl: 2017.0.4-h6d528fc_0 defaults --> 2018.0.3-1 defaults
The following packages will be DOWNGRADED:
numpy: 1.11.3-py34_0 defaults --> 1.10.1-py34_0 defaults pandas: 0.19.2-np111py34_1 defaults --> 0.18.1-np110py34_0 defaults scikit-learn: 0.18.1-np111py34_1 defaults --> 0.17-np110py34_1 defaults scipy: 0.19.1-np111py34_0 defaults --> 0.16.0-np110py34_0 defaults
Method 8
I struggled trying to figure this one out; tried to download and install the (unofficial) Numpy+MKL library from the website (risky/tedious?).
Ultimately found success by:
- Login to command prompt using admin rights; how to here: https://superuser.com/questions/968214/open-cmd-as-admin-with-windowsr-shortcut
-
Uninstall existing/tangled version of Scipy & Numpy
pip uninstall scipy
pip uninstall numpy
-
Fresh install Scipy & Numpy
pip install scipy
pip install numpy
- Run Jupyter notebook; it worked for me.
The message ImportError: DLL load failed: The specified module could not be found
informs that there is failure to identify and source the required DLL(s) to use the scikit-learn library; a fresh install of scipy/numpy probably enables a better routing of DLL connections called from Jupyter notebook code(s).
Method 9
download microsoft visual c++ distribution
link : https://www.microsoft.com/en-in/download/details.aspx?id=53840
vc_redist.x64.exe
install and run this .exe file in your computer.. the DLL import module error will not appear after this
now it will work fine enjoy 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0