Search code examples
scikit-learnpython-3.7importerror

ImportError while importing sklearn


I am using python 3.7 Recently I started getting this error while importing sklearn module. I get the same error in Jupyter Notebook, Python IDLE, Pycharm virtual environment

>>> import sklearn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\aditya\AppData\Roaming\Python\Python37\site-packages\sklearn\__init__.py", line 75, in <module>
    from .utils._show_versions import show_versions
  File "C:\Users\aditya\AppData\Roaming\Python\Python37\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.

I have tried reinstalling too. After that I copied contents of sklearn of venv of another project which had no issues. This thing worked for couple of times. But now it's not working again

Note: pandas, numpy, scipy etc are installed and working absolutely fine. Sklearn was also working fine few days back


Solution

  • This is an issue in the packaging in scikit-learn 0.22.0 which will be solved in 0.22.1 (released next week). The issue is tracked at: github.com/scikit-learn/scikit-learn/issues/15899. There are 2 possible workarounds: