0
votes

Okay, I have seen at least 8 versions of this questions scattered across GitHub and Stackoverflow with no resolution. In addition, it appears it has popped up more lately than in the past (See references at the end)

When I trying a simple import of Sklearn, I keep getting a "Import Error: DLL load failed"

import scipy
# works
import sklearn
# crashes
import scipy.linalg
# crashes
print(sklearn.__version__)

Full error output:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sam\Documents\thesiscode\venv\lib\site-packages\sklearn\__init__.py", line 80, in <module>
    from .base import clone
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sam\Documents\thesiscode\venv\lib\site-packages\sklearn\base.py", line 21, in <module>
    from .utils import _IS_32BIT
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sam\Documents\thesiscode\venv\lib\site-packages\sklearn\utils\__init__.py", line 27, in <module>
    from .fixes import np_version
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sam\Documents\thesiscode\venv\lib\site-packages\sklearn\utils\fixes.py", line 18, in <module>
    import scipy.stats
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sam\Documents\thesiscode\venv\lib\site-packages\scipy\stats\__init__.py", line 384, in <module>
    from .stats import *
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sam\Documents\thesiscode\venv\lib\site-packages\scipy\stats\stats.py", line 179, in <module>
    from scipy.spatial.distance import cdist
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sam\Documents\thesiscode\venv\lib\site-packages\scipy\spatial\__init__.py", line 102, in <module>
    from ._procrustes import procrustes
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sam\Documents\thesiscode\venv\lib\site-packages\scipy\spatial\_procrustes.py", line 11, in <module>
    from scipy.linalg import orthogonal_procrustes
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sam\Documents\thesiscode\venv\lib\site-packages\scipy\linalg\__init__.py", line 195, in <module>
    from .misc import *
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sam\Documents\thesiscode\venv\lib\site-packages\scipy\linalg\misc.py", line 5, in <module>
    from .blas import get_blas_funcs
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sam\Documents\thesiscode\venv\lib\site-packages\scipy\linalg\blas.py", line 215, in <module>
    from scipy.linalg import _fblas
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ImportError: DLL load failed: The specified module could not be found.

I know that this is referencing that it is a SciPy problem, but I cannot for the life of me fix it. I have read almost every question out there with no resolve. I have tried:

  • Uninstall and reinstalling SciPy, scikit-learn, numpy, etc with standard packages.

  • Uninstall and reinstalling all packages with unofficial packages (.whl files) from https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy using pip install --upgrade --force-reinstall "numpy‑1.16.3+mkl‑cp37‑cp37m‑win32.whl" with the correct file names

  • Downgrading SciPy and scikit-learn to earlier versions

  • I have destroyed and created new virtual environments in PyCharm and tried using their installs via Project Interpreter (yes, I have double checked that the interpreter path is correct too)

I have tried a couple more things related to packages, paths, and installs but still the DLL load error persists. How can I resolve this error? Does anyone know what causes this? From online, it definitely seems directly related to Windows 10, PyCharm, and SciPy

Environment information:

  • Standard Dell running Windows 10

  • PyCharm 2020 Pro Edition running Python 3.7.7

  • scipy 1.4.1 (tried 1.4.0)

  • scikit-learn 0.23.1 (tried 0.22.1? and 0.21.3)

  • numpy 1.18.4 (tried numpy+MKL .whl package suggested in first link)

Here are all the questions AND a link to the GitHub sklearn guys talking about it, but they say it is a "usage error". None of these gave me any resolution

Error importing scikit-learn modules

https://github.com/scikit-learn/scikit-learn/issues/15899

sklearn. ImportError: DLL load failed

ImportError when importing certain modules from SciPY

ImportError: DLL load failed, with import sklearn

1
What is sklearn 0.0?desertnaut
I thought that was odd too, but that was the version number when I checked every time.Sam Dean
It might very well be the cause of the error. Try uninstalling & reinstalling scikit-learn.desertnaut
Is there another way to do that? I have tried pip uninstall on all packages 10 times and tried the uninstall/install on PyCharm.Sam Dean

1 Answers

0
votes

Seems that this is a Windows, PyCharm, and Sklearn combination issue. I switched to a Linux VM running Pycharm and Sklearn, and it works fine.