Importing Kmeans from sklearn suddenly stopped working - python

I've loaded my Jupyter notebook as usual, when the only thing I changed is the Numpy version to 1.21.4.
However once I imported Kmeans from sklearn.cluster import KMeans I received the following error:
ImportError: DLL load failed while importing lapack_lite: The specified module could not be found.
I've tried the solution given in the link here, but it didn't help: ImportError: DLL load failed: The specified module could not be found
I've also tried to reinstall scikit-learn, but it also didn't help. So did restarting the kernel and the notebook didn't help.
My scikit-learn version is 1.1.1
I code on the same code on my laptop and on my desktop PC. On my laptop the code runs good the this specific import won't produce this error. But on my desktop PC, it does produce this error, which is strange because the scikit-learn and numpy versions are the same on both my desktop PC and laptop.
How can I fix this issue?

Related

Jupyter notebook : Import error: DLL load failed (but works on .py) without Anaconda

I was trying to use CuPy inside a Jupyter Notebook on Windows10 and got this error :
---> from cupy_backends.cuda.libs import nvrtc
ImportError: DLL load failed while importing nvrtc: The specified procedure could not be found.
This is triggered by import cupy.
I know there is a bunch of threads about similar issues (DLLs not found by Jupyter under Windows), but everyone of them relies on conda, that I'm not using anymore.
I checked os.environ['CUDA_PATH'], which is set to C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6 and is the right path.
Also, os.environ['PATH'] contains C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6\\bin which is where the DLL is located.
I fixed it once by running pip install -U notebook, then it started failing again after restarting Jupyter. Running the same command (even with --force-reinstall) could not produce the same effect again.
I have no problems with CuPy when using a shell or a regular Python IDE. I could use workarounds like executing CuPy based commands outside Jupyter for myself, but that would go against using notebooks for pedagogy and examples, which is my major use of notebooks.
Would anyone have a fix for that not relying on conda ?
The error was showing up because I was importing PyTorch before CuPy.
Solution was to import cupy before torch.

Cannot import from sklearn.feature_extraction.text import CountVectorizer

I'm trying to import CountVectorizer from sklearn with the following line:
from sklearn.feature_extraction.text import CountVectorizer
sklearn: 0.0
scikit-learn: 0.23.2
numpy: 1.19.2
scipy: 1.5.2
threadpoolctl: 2.1.0
joblib: 0.17.0
Every time I try to run the code I receive the following error:
No name 'feature_extraction' in module 'sklearn' pylint(no-name-in-module)
Unable to import 'sklearn.feature_extraction.text' pylint(import-error)
If it matters I am running this in vscode on a Linux system inside of a VM. Also, I was able to run it earlier on the VM and it just stopped working for no apparent reason.
I found out the reason why for some reason my vscode was saving my file as .pyc and it wouldn't recognize the library with pyc. If anyone else experiences this problem note my file still said py but auto-generated a pycache folder.
because sklearn is deprecated
try this :
pip install scikit-learn

Python Scikit learn script crashing in Windows Task Scheduler

I have a python script using Scikit-learn libraries and it works completely fine when I run it manually in either Jupyter notebook or command line. However, it doesn't work when I schedule it in Windows Task Scheduler. After spending a lot of time I realised the issue is due to the sklearn imports. If I comment out the sklearn imports, the script works fine in the scheduler but the moment I include a sklearn import, the scheduler doesn't execute one line of the script. I have no idea what is causing this and it's even more surprising that the script works like a charm when running it manually. I've uninstalled and reinstalled Anaconda distribution on my PC but no result. Any help on how I can fix this please?
I finally managed to fix this. Turns out it's a corrupted scipy package. Uninstalling and re-installing it fixed the issue.
The way I figured it out is by running my python script as a batch file which threw the following error
from scipy.sparse.linalg import lsqr as sparse_lsqr
ImportError: DLL load failed: The specified module could not be found.
I never got this error when I ran my python script from the windows scheduler or Jupyter notebook or even command line, which is very strange.

Numpy failing on import (ImportError: DLL load failed: The network path was not found.)

I had python with numpy installed and working fine on my local device for years, but for some reason, I get the error:
ImportError: Importing the multiarray numpy extension module failed.
Most likely you are trying to import a failed build of numpy. If
you're working with a numpy git repo, try git clean -xdf (removes
all files not under version control). Otherwise, reinstall numpy.
The original error was:
DLL load failed: The network path was not found.
depending on what network I'm connected to. reinstalling seems to fix it but my bigger concern is why the network status affects it at all? What DLL is it trying to find and where is it trying to get it from?

from scipy.interpolate import UnivariateSpline: Importerror [duplicate]

I'm trying to upload the curve_fit from scipy.optimize to fit an exponential function to some data I have generated. My code looks like:
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
When I run the code, I get the following error:
ImportError: DLL load failed: The specified module could not be found.
I have scipy in an Anaconda folder on my computer, and I'm 80% sure I installed it. How do I fix this error? (Or if you have a better way of fitting an exponential function to data, I'm all ears)
Thanks!
edit: Here is the full error:
Traceback (most recent call last):
File "C:\Users\Casey\Documents\Python\Perc_MatPlot3.py", line 10
from scipy.optimize import curve_fit
File "C:\Users\Casey\Anaconda\Lib\site-packages\scipy\optimize\__init__.py", line 146
from .optimize import *
File "C:\Users\Casey\Anaconda\Lib\site-packages\scipy\optimize\optimize.py", line 35
from .linesearch import (line_search_BFGS, line_search_wolfe1,
File "C:\Users\Casey\Anaconda\Lib\site-packages\scipy\optimize\linesearch.py", line 16
from scipy.optimize import minpack2
ImportError: DLL load failed: The specified module could not be found.
I encountered the error
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
when using cgoehlke's "Unofficial Windows Binaries for Python Extension Packages" for SciPy with a pip3-installed NumPy, overlooking this note:
Many binaries depend on NumPy-1.9+MKL and ...
Their NumPy provides the missing DLLs / modules.
I've run into several problems like this recently when trying to use pyplot and scipy. I have Anaconda 2.7, 32bit running on Windows 7 x64
I just encountered this exact error whilst trying to use curve_fit. I downloaded the 'superpack' from sourceforge: http://sourceforge.net/projects/scipy/
Running this installer fixed the error and didn't affect any other part of my python environment.
I was suffering from exactly the same problem.
from scipy.optimize import minpack2
I reinstalled numpy and MLK but still got this error on Pycharm. I directly update my python to 3.6 and now the problem is solved.
During the procedure, use
conda install python=3.6
Since
conda update python
showed me that I already have the 3.5.2, which means conda update failed to update from 3.5 to 3.6 and it is supposed to be capable of upgrading from versions like 3.5.1-->3.5.2 I think.
Hope this could help. Plus, remember to reset the environment after the update.
Not sure if this is an answer for you, because this error can mean so many things... I've been there...
I just had the same error (also while loading Scipy optimize) just 10 minutes ago with a fresh install of Miniconda for Python 3.3 on a Vista x64 machine. Somehow it failed to add the main Python directory to the Windows PATH (and I'm pretty sure I didn't uncheck the box for it at the end of the installation).
I did the same procedure on some XP and Windows 7 machines earlier this week without any problems, so i caught me a bit by surprise.
If you have no other Python installation on your machine, you can check if running 'python' (type win-key + r, or do it from command prompt) works. If it doesn't, simply add your main installation directory (where python.exe is located) to your PATH variable.
If this doesn't work you could use Dependency Walker to check which DLL the error message is actually about, and then see if that DLL is present somewhere within your PATH or PYTHONPATH.
I have had the same DLL error when multiple versions of the same DLL were compiled with different compilers and the required version wasn't found first. If removing a version (the program it came with) isn't an option, changing the order of your PATH variable can help.
This is most likely you installed 32-bit Python but 64-bit libraries or vice versa.
You need to remove Python and reinstall correct python.
https://www.python.org/download/
Here you can download Python.
Remember you python libraries should be the same 32bit or 64bit as the one of Python.

Categories