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:\Python34\lib\site-packages\sklearn\cluster\__init__.py", line 6, in <module>
from .spectral import spectral_clustering, SpectralClustering
File "C:\Python34\lib\site-packages\sklearn\cluster\spectral.py", line 13, in <module>
from ..utils import check_random_state, as_float_array
File "C:\Python34\lib\site-packages\sklearn\utils\__init__.py", line 16, in <module>
from .class_weight import compute_class_weight, compute_sample_weight
File "C:\Python34\lib\site-packages\sklearn\utils\class_weight.py", line 7, in <module>
from ..utils.fixes import in1d
File "C:\Python34\lib\site-packages\sklearn\utils\fixes.py", line 318, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\__init__.py", line 109, in <module>
from .isolve import *
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
from .iterative import *
File "C:\Python34\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.
I'm using Python 3.4 on Windows, scikit-learn 0.16.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
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.
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 Anaconda3\Lib\site-packages\scipy\special\_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 Anaconda3\pkgs\mkl-2017.0.3-0\Library\bin 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.
From the error log, it shows that scipy module is the most recent module fails to import
File "C:\Python34\lib\site-packages\sklearn\utils\fixes.py", line 318, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\__init__.py", line 109, in <module>
from .isolve import *
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
from .iterative import *
File "C:\Python34\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.
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
Place this line on top of the python file
from sklearn import cluster
That should do it :))
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
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
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).
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 :)
Related
I am using the windows command prompt to install the scikit learn library using the command pip install -U scikit-learn. However, whenever I try to import it into my program I get an error stating that there is no module named 'sklearn'. Also, whenever I download the library using pip, for some reason, my pip package installer seems to break and pip is no longer recognized as a command on my cmd. I have numerous other modules which work perfectly fine so I don't see a reason as to why I can't get this specific library to work. I am still quite new to this kind of thing, so maybe I am missing something.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in
import sklearn
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn_init_.py", line 82, in
from .base import clone
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\base.py", line 17, in
from .utils import IS_32BIT
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils_init.py", line 20, in
from scipy.sparse import issparse
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse_init_.py", line 227, in
from .base import *
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse\base.py", line 4, in
from .sputils import (isdense, isscalarlike, isintlike,
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse\sputils.py", line 8, in
from scipy._lib._util import prod
ModuleNotFoundError: No module named 'scipy._lib._util'
Try to upgrade pip to newest version by python -m pip install --upgrade pip considering you are still using Windows. And then try to download sciKitLearn by pip install sklearn
This is how I had solved my problem but keep note that it was about a year ago
If all this doesn't work, try VirtualEnv.
I have used
from sklearn.linear_model import LinearRegression
and getting the following errors
Traceback (most recent call last):
File "F:/PyProjects/LRtest.py", line 2, in <module>
from sklearn.linear_model import LinearRegression
File "F:\PyProjects\venv\lib\site-packages\sklearn\__init__.py", line 75, in <module>
from .utils._show_versions import show_versions
File "F:\PyProjects\venv\lib\site-packages\sklearn\utils\_show_versions.py", line 12, in <module>
from ._openmp_helpers import _openmp_parallelism_enabled
ImportError: DLL load failed: The specified module could not be found.
As recommended on earlier questions:
I have uninstalled numpy, sklearn, scikit-learn, scipy and also reinstalled them.
But that does not seem to work for my problem.
Can you tell what does this mean? And also recommend how to solve this?
ImportError: DLL load failed: The specified module could not be found.
I am using
Windows 10, PyCharm Pro 2019-3, Python v3.6, and lib versions given in the image
The package is called scikit-learn, not sklearn. From inside of Python, it is called sklearn. How do you have an entry for sklearn in your package list there with version 0?
Try uninstalling 'sklearn'. You already have the real scikit-learn, so maybe it will do the right thing once the false package is removed.
If that doesn't work, I would create a new python environment from scratch and reinstall the right packages there...
https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
That way you know that you're starting with a clean slate.
First, uninstall numpy and scipy from your command prompt.
pip uninstall numpy
pip uninstall scipy
After that install numpy and scipy from this website.
https://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy
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
This line points to scipy.
from scipy.sparse.linalg import lsqr as sparse_lsqr
You can try:
pip uninstall scipy
pip install scipy
enjoy!
Reinstallation of scipy, numpy, and scikit-learn packages fixed the error in my case.
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.
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.
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
}
For me uninstalling scipy in conda env and then reinstalling using pip works.
Uninstall: conda remove --force scipy
Install: pip install scipy
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.
pip install --user --upgrade numpy
pip install --user --upgrade scipy
pip install --user --upgrade matplotlib
pip install --user --upgrade scikit-learn
I've used pip to install the module numpy (sudo pip install numpy).This works fine.
When importing numpy for use in my own module i get several the following errors.
Traceback (most recent call last):
File "<pyshell#65>", line 1, in <module>
import numpy
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/multiarray.so, 2): Symbol not found: _PyBuffer_Type
Referenced from: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/multiarray.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/multiarray.so
I'm assuming the error has something to do with the multiarray.so file. I've tried turning it off and on (uninstall re install) and adding the where pip initially saves the module to python export path
(export PYTHONPATH="usr/local/lib/python2.7/site-packages")
doesn't seem to work.
Using which python in terminal gives me Python 2.7.6**, however I downloaded python 3.5 off of the site.
Issue resolved.
The reason i was having installation issues with pip, was down to the fact (thanks pv) that i was using the command:
"pip install moduleName"
rather than
"pip3.5 install moduleName"
this caused all sorts of complications, because i'm running python 3.5 and the "pip" command is for 2.7.
Thanks again.
FWIW -- and for people in the future who are googling for this error -- I ran into this issue when installing numpy separately via Homebrew. It caused all my installations of Python (via pyenv) to refer to the /usr/local/lib installation of numpy (which is where Homebrew installs it). Uninstalling it via brew uninstall numpy fixed the error.
(I don't remember why I had a homebrew-installed numpy, but oh well)
I encountered the same problem.
I tried many ways like:
$pip uninstall numpy
But that did not fix the problem.
I assume a major reason is that I have anaconda multi-Python environments (I have created both py27 and py35). As a result the PYTHONPATH includes paths for both py27 and py35.
My default python env is py35. So using
$conda install numpy
will install numpy under the anaconda python3.5 path.
When uninstalling the numpy, we are not sure which numpy path is exporting, maybe it is only for my case.
Hence I refer to #Dan Nhuyen's solution.
I uninstall numpy via:
$brew uninstall numpy.
As a result, the extra ambiguous paths is removed. Finally, it works.
What worked for me was to request pip to build numpy from source, instead of using the pre-compiled wheel binary:
pip install --no-binary numpy -r requirements.txt
I'm tired to import cv and numpy and get errors. I started importing cv and I got this error:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "", line 1, in <module>
File "/usr/lib/pymodules/python2.7/cv.py", line 1, in <module>
from cv2.cv import *
ImportError: numpy.core.multiarray failed to import
So I installed numpy on Ubuntu using:
apt-get install python-numpy
So when I import numpy I get:
Traceback (most recent call last):
File "", line 1, in <module>
File "numpy/init.py", line 127, in <module>
raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
I really need help. I'm using Python 2.7.3 on Ubuntu.
There is nothing wrong with installing common dependencies using your operating system's package manager, remember using pip means your synaptic updates won't update your Python libraries and pip won't leverage the dependencies already taken care of by aptitude. For python packages with C extensions like numpy and opencv its probably better to use apt-get.
In Ubuntu you can install both dependencies with
sudo apt-get install python-numpy python-opencv
The actual Python error you are getting indicates what is wrong, namely that you are executing from within the numpy source directory, or have a file named numpy.py in your current directory which is confusing things at import time. Try change into an empty directory, start Python import your libraries:
import numpy
import cv
Hope that helps.
It's better that use some package management tool such like pip to install numpy.
For example,
pip install numpy