title: Issue importing scikit-learn: module 'scipy' has no attribute '_lib'
body: <p>I'm new to Python and am using Anaconda on Windows 10 to learn how to implement machine learning. Running this code on Spyder:</p>
  
  <pre class="lang-py prettyprint-override"><code>import sklearn as skl
  </code></pre>
  
  <p>Originally got me this:</p>
  
  <pre><code>Traceback (most recent call last):
  
    File "&lt;ipython-input-1-7135d3f24347&gt;", line 1, in &lt;module&gt;
      runfile('C:/Users/julia/.spyder-py3/temp.py', wdir='C:/Users/julia/.spyder-py3')
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
      execfile(filename, namespace)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
      exec(compile(f.read(), filename, 'exec'), namespace)
  
    File "C:/Users/julia/.spyder-py3/temp.py", line 3, in &lt;module&gt;
      from sklearn.family import Model
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\__init__.py", line 76, in &lt;module&gt;
      from .base import clone
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\base.py", line 16, in &lt;module&gt;
      from .utils import _IS_32BIT
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\__init__.py", line 20, in &lt;module&gt;
      from .validation import (as_float_array,
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 21, in &lt;module&gt;
      from .fixes import _object_dtype_isnan
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\fixes.py", line 289, in &lt;module&gt;
      from scipy.sparse.linalg import lsqr as sparse_lsqr
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\sparse\linalg\__init__.py", line 114, in &lt;module&gt;
      from .isolve import *
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in &lt;module&gt;
      from .iterative import *
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 10, in &lt;module&gt;
      from . import _iterative
  
  ImportError: DLL load failed: The specified module could not be found.
  </code></pre>
  
  <p>I then went to the command line and did</p>
  
  <pre><code>pip uninstall scipy
  pip install scipy
  
  pip uninstall scikit-learn
  pip install scikit-learn
  </code></pre>
  
  <p>and got no errors when doing so, with scipy 1.3.1 (along with numpy 1.17.0) and scikit-learn 0.21.3 being installed according to the command line.</p>
  
  <p>However, now when I try to import sklearn I get a different error:</p>
  
  <pre><code> File "&lt;ipython-input-2-7135d3f24347&gt;", line 1, in &lt;module&gt;
      runfile('C:/Users/julia/.spyder-py3/temp.py', wdir='C:/Users/julia/.spyder-py3')
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
      execfile(filename, namespace)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
      exec(compile(f.read(), filename, 'exec'), namespace)
  
    File "C:/Users/julia/.spyder-py3/temp.py", line 3, in &lt;module&gt;
      from sklearn.family import Model
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\__init__.py", line 76, in &lt;module&gt;
      from .base import clone
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\base.py", line 16, in &lt;module&gt;
      from .utils import _IS_32BIT
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\__init__.py", line 20, in &lt;module&gt;
      from .validation import (as_float_array,
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 21, in &lt;module&gt;
      from .fixes import _object_dtype_isnan
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\fixes.py", line 289, in &lt;module&gt;
      from scipy.sparse.linalg import lsqr as sparse_lsqr
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\sparse\linalg\__init__.py", line 113, in &lt;module&gt;
      from .isolve import *
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in &lt;module&gt;
      from .iterative import *
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 136, in &lt;module&gt;
      def bicg(A, b, x0=None, tol=1e-5, maxiter=None, M=None, callback=None, atol=None):
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\_lib\_threadsafety.py", line 59, in decorator
      return lock.decorate(func)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\_lib\_threadsafety.py", line 47, in decorate
      return scipy._lib.decorator.decorate(func, caller)
  
  AttributeError: module 'scipy' has no attribute '_lib'
  </code></pre>
  
  <p>Any suggestions? I've uninstalled and reinstalled Anaconda and I'm still getting the same issue.</p>
  
  <p>EDIT: When I do </p>
  
  <pre><code>conda list --show-channel-urls
  </code></pre>
  
  <p>I get</p>
  
  <pre><code># packages in environment at C:\ProgramData\Anaconda3:
  #
  # Name                    Version                   Build  Channel
  _ipyw_jlab_nb_ext_conf    0.1.0                    py37_0    defaults
  alabaster                 0.7.12                   py37_0    defaults
  anaconda-client           1.7.2                    py37_0    defaults
  anaconda-navigator        1.9.7                    py37_0    defaults
  asn1crypto                0.24.0                   py37_0    defaults
  astroid                   2.2.5                    py37_0    defaults
  attrs                     19.1.0                   py37_1    defaults
  babel                     2.7.0                      py_0    defaults
  backcall                  0.1.0                    py37_0    defaults
  backports                 1.0                        py_2    defaults
  backports.functools_lru_cache 1.5                        py_2    defaults
  backports.tempfile        1.0                        py_1    defaults
  backports.weakref         1.0.post1                  py_1    defaults
  beautifulsoup4            4.7.1                    py37_1    defaults
  blas                      1.0                         mkl    defaults
  bleach                    3.1.0                    py37_0    defaults
  bzip2                     1.0.8                he774522_0    defaults
  ca-certificates           2019.5.15                     1    defaults
  certifi                   2019.6.16                py37_1    defaults
  cffi                      1.12.3           py37h7a1dbc1_0    defaults
  chardet                   3.0.4                 py37_1003    defaults
  click                     7.0                      py37_0    defaults
  cloudpickle               1.2.1                      py_0    defaults
  clyent                    1.2.2                    py37_1    defaults
  colorama                  0.4.1                    py37_0    defaults
  conda                     4.7.11                   py37_0    defaults
  conda-build               3.18.8                   py37_0    defaults
  conda-env                 2.6.0                         1    defaults
  conda-package-handling    1.3.11                   py37_0    defaults
  conda-verify              3.4.2                      py_1    defaults
  console_shortcut          0.1.1                         3    defaults
  cryptography              2.7              py37h7a1dbc1_0    defaults
  decorator                 4.4.0                    py37_1    defaults
  defusedxml                0.6.0                      py_0    defaults
  docutils                  0.15.1                   py37_0    defaults
  entrypoints               0.3                      py37_0    defaults
  filelock                  3.0.12                     py_0    defaults
  freetype                  2.9.1                ha9979f8_1    defaults
  future                    0.17.1                   py37_0    defaults
  glob2                     0.7                        py_0    defaults
  icc_rt                    2019.0.0             h0cc432a_1    defaults
  icu                       58.2                 ha66f8fd_1    defaults
  idna                      2.8                      py37_0    defaults
  imagesize                 1.1.0                    py37_0    defaults
  intel-openmp              2019.4                      245    defaults
  ipykernel                 5.1.1            py37h39e3cac_0    defaults
  ipython                   7.7.0            py37h39e3cac_0    defaults
  ipython_genutils          0.2.0                    py37_0    defaults
  ipywidgets                7.5.1                      py_0    defaults
  isort                     4.3.21                   py37_0    defaults
  jedi                      0.13.3                   py37_0    defaults
  jinja2                    2.10.1                   py37_0    defaults
  joblib                    0.13.2                   py37_0    defaults
  jpeg                      9b                   hb83a4c4_2    defaults
  json5                     0.8.5                      py_0    defaults
  jsonschema                3.0.1                    py37_0    defaults
  jupyter_client            5.3.1                      py_0    defaults
  jupyter_core              4.5.0                      py_0    defaults
  jupyterlab                1.0.2            py37hf63ae98_0    defaults
  jupyterlab_server         1.0.0                      py_1    defaults
  keyring                   18.0.0                   py37_0    defaults
  lazy-object-proxy         1.4.1            py37he774522_0    defaults
  libarchive                3.3.3                h0643e63_5    defaults
  libiconv                  1.15                 h1df5818_7    defaults
  liblief                   0.9.0                ha925a31_2    defaults
  libpng                    1.6.37               h2a8f88b_0    defaults
  libsodium                 1.0.16               h9d3ae62_0    defaults
  libtiff                   4.0.10               hb898794_2    defaults
  libxml2                   2.9.9                h464c3ec_0    defaults
  lz4-c                     1.8.1.2              h2fa13f4_0    defaults
  lzo                       2.10                 h6df0209_2    defaults
  m2w64-gcc-libgfortran     5.3.0                         6    defaults
  m2w64-gcc-libs            5.3.0                         7    defaults
  m2w64-gcc-libs-core       5.3.0                         7    defaults
  m2w64-gmp                 6.1.0                         2    defaults
  m2w64-libwinpthread-git   5.0.0.4634.697f757               2    defaults
  markupsafe                1.1.1            py37he774522_0    defaults
  mccabe                    0.6.1                    py37_1    defaults
  menuinst                  1.4.16           py37he774522_0    defaults
  mistune                   0.8.4            py37he774522_0    defaults
  mkl                       2019.4                      245    defaults
  mkl-service               2.0.2            py37he774522_0    defaults
  mkl_fft                   1.0.12           py37h14836fe_0    defaults
  mkl_random                1.0.2            py37h343c172_0    defaults
  msys2-conda-epoch         20160418                      1    defaults
  navigator-updater         0.2.1                    py37_0    defaults
  nbconvert                 5.5.0                      py_0    defaults
  nbformat                  4.4.0                    py37_0    defaults
  notebook                  6.0.0                    py37_0    defaults
  numpy                     1.17.0                   pypi_0    pypi
  numpy-base                1.16.4           py37hc3f5095_0    defaults
  numpydoc                  0.9.1                      py_0    defaults
  olefile                   0.46                     py37_0    defaults
  openssl                   1.1.1c               he774522_1    defaults
  packaging                 19.0                     py37_0    defaults
  pandas                    0.25.0           py37ha925a31_0    defaults
  pandoc                    2.2.3.2                       0    defaults
  pandocfilters             1.4.2                    py37_1    defaults
  parso                     0.5.0                      py_0    defaults
  pickleshare               0.7.5                    py37_0    defaults
  pillow                    6.1.0            py37hdc69c19_0    defaults
  pip                       19.2.2                   pypi_0    pypi
  pkginfo                   1.5.0.1                  py37_0    defaults
  powershell_shortcut       0.0.1                         2    defaults
  prometheus_client         0.7.1                      py_0    defaults
  prompt_toolkit            2.0.9                    py37_0    defaults
  psutil                    5.6.3            py37he774522_0    defaults
  py-lief                   0.9.0            py37ha925a31_2    defaults
  pycodestyle               2.5.0                    py37_0    defaults
  pycosat                   0.6.3            py37hfa6e2cd_0    defaults
  pycparser                 2.19                     py37_0    defaults
  pyflakes                  2.1.1                    py37_0    defaults
  pygments                  2.4.2                      py_0    defaults
  pylint                    2.3.1                    py37_0    defaults
  pyopenssl                 19.0.0                   py37_0    defaults
  pyparsing                 2.4.0                      py_0    defaults
  pyqt                      5.9.2            py37h6538335_2    defaults
  pyrsistent                0.14.11          py37he774522_0    defaults
  pysocks                   1.7.0                    py37_0    defaults
  python                    3.7.3                h8c8aaf0_1    defaults
  python-dateutil           2.8.0                    py37_0    defaults
  python-libarchive-c       2.8                     py37_13    defaults
  pytz                      2019.1                     py_0    defaults
  pywin32                   223              py37hfa6e2cd_1    defaults
  pywinpty                  0.5.5                 py37_1000    defaults
  pyyaml                    5.1.1            py37he774522_0    defaults
  pyzmq                     18.0.0           py37ha925a31_0    defaults
  qt                        5.9.7            vc14h73c81de_0    defaults
  qtawesome                 0.5.7                    py37_1    defaults
  qtconsole                 4.5.2                      py_0    defaults
  qtpy                      1.8.0                      py_0    defaults
  requests                  2.22.0                   py37_0    defaults
  rope                      0.14.0                     py_0    defaults
  ruamel_yaml               0.15.46          py37hfa6e2cd_0    defaults
  scikit-learn              0.21.3                   pypi_0    pypi
  scipy                     1.3.0                    pypi_0    pypi
  send2trash                1.5.0                    py37_0    defaults
  setuptools                41.0.1                   py37_0    defaults
  sip                       4.19.8           py37h6538335_0    defaults
  six                       1.12.0                   py37_0    defaults
  snowballstemmer           1.9.0                      py_0    defaults
  soupsieve                 1.9.2                    py37_0    defaults
  sphinx                    2.1.2                      py_0    defaults
  sphinxcontrib-applehelp   1.0.1                      py_0    defaults
  sphinxcontrib-devhelp     1.0.1                      py_0    defaults
  sphinxcontrib-htmlhelp    1.0.2                      py_0    defaults
  sphinxcontrib-jsmath      1.0.1                      py_0    defaults
  sphinxcontrib-qthelp      1.0.2                      py_0    defaults
  sphinxcontrib-serializinghtml 1.1.3                      py_0    defaults
  spyder                    3.3.6                    py37_0    defaults
  spyder-kernels            0.5.1                    py37_0    defaults
  sqlite                    3.29.0               he774522_0    defaults
  terminado                 0.8.2                    py37_0    defaults
  testpath                  0.4.2                    py37_0    defaults
  tk                        8.6.8                hfa6e2cd_0    defaults
  tornado                   6.0.3            py37he774522_0    defaults
  tqdm                      4.32.1                     py_0    defaults
  traitlets                 4.3.2                    py37_0    defaults
  urllib3                   1.24.2                   py37_0    defaults
  vc                        14.1                 h0510ff6_4    defaults
  vs2015_runtime            14.15.26706          h3a45250_4    defaults
  wcwidth                   0.1.7                    py37_0    defaults
  webencodings              0.5.1                    py37_1    defaults
  wheel                     0.33.4                   py37_0    defaults
  widgetsnbextension        3.5.0                    py37_0    defaults
  win_inet_pton             1.1.0                    py37_0    defaults
  wincertstore              0.2                      py37_0    defaults
  winpty                    0.4.3                         4    defaults
  wrapt                     1.11.2           py37he774522_0    defaults
  xz                        5.2.4                h2fa13f4_4    defaults
  yaml                      0.1.7                hc54c509_2    defaults
  zeromq                    4.3.1                h33f27b4_3    defaults
  zlib                      1.2.11               h62dcd97_3    defaults
  zstd                      1.3.7                h508b16e_0    defaults
  </code></pre>
  
  <p>with the version of scipy not matching up with the version that pip installed. Not sure how significant it is but it seemed strange to me.</p>
  
  <p>EDIT 2:
  Doing <code>pip list</code> returns</p>
  
  <pre><code>Package                       Version
  ----------------------------- ---------
  -cipy                         1.3.0
  alabaster                     0.7.12
  anaconda-client               1.7.2
  anaconda-navigator            1.9.7
  asn1crypto                    0.24.0
  astroid                       2.2.5
  attrs                         19.1.0
  Babel                         2.7.0
  backcall                      0.1.0
  backports.functools-lru-cache 1.5
  backports.tempfile            1.0
  backports.weakref             1.0.post1
  beautifulsoup4                4.7.1
  bleach                        3.1.0
  certifi                       2019.6.16
  cffi                          1.12.3
  chardet                       3.0.4
  Click                         7.0
  cloudpickle                   1.2.1
  clyent                        1.2.2
  colorama                      0.4.1
  conda                         4.7.11
  conda-build                   3.18.8
  conda-package-handling        1.3.11
  conda-verify                  3.4.2
  cryptography                  2.7
  decorator                     4.4.0
  defusedxml                    0.6.0
  docutils                      0.15.1
  entrypoints                   0.3
  filelock                      3.0.12
  future                        0.17.1
  glob2                         0.7
  idna                          2.8
  imagesize                     1.1.0
  ipykernel                     5.1.1
  ipython                       7.7.0
  ipython-genutils              0.2.0
  ipywidgets                    7.5.1
  isort                         4.3.21
  jedi                          0.13.3
  Jinja2                        2.10.1
  joblib                        0.13.2
  json5                         0.8.5
  jsonschema                    3.0.1
  jupyter-client                5.3.1
  jupyter-core                  4.5.0
  jupyterlab                    1.0.2
  jupyterlab-server             1.0.0
  keyring                       18.0.0
  lazy-object-proxy             1.4.1
  libarchive-c                  2.8
  MarkupSafe                    1.1.1
  mccabe                        0.6.1
  menuinst                      1.4.16
  mistune                       0.8.4
  mkl-fft                       1.0.12
  mkl-random                    1.0.2
  mkl-service                   2.0.2
  navigator-updater             0.2.1
  nbconvert                     5.5.0
  nbformat                      4.4.0
  notebook                      6.0.0
  numpy                         1.17.0
  numpydoc                      0.9.1
  olefile                       0.46
  packaging                     19.0
  pandas                        0.25.0
  pandocfilters                 1.4.2
  parso                         0.5.0
  pickleshare                   0.7.5
  Pillow                        6.1.0
  pio                           0.0.3
  pip                           19.2.2
  pkginfo                       1.5.0.1
  prometheus-client             0.7.1
  prompt-toolkit                2.0.9
  psutil                        5.6.3
  pycodestyle                   2.5.0
  pycosat                       0.6.3
  pycparser                     2.19
  pyflakes                      2.1.1
  Pygments                      2.4.2
  pylint                        2.3.1
  pyOpenSSL                     19.0.0
  pyparsing                     2.4.0
  pyrsistent                    0.14.11
  PySocks                       1.7.0
  python-dateutil               2.8.0
  pytz                          2019.1
  pywin32                       223
  pywinpty                      0.5.5
  PyYAML                        5.1.1
  pyzmq                         18.0.0
  QtAwesome                     0.5.7
  qtconsole                     4.5.2
  QtPy                          1.8.0
  requests                      2.22.0
  rope                          0.14.0
  ruamel-yaml                   0.15.46
  scikit-learn                  0.21.3
  scipy                         1.3.1
  Send2Trash                    1.5.0
  setuptools                    41.0.1
  six                           1.12.0
  snowballstemmer               1.9.0
  soupsieve                     1.9.2
  Sphinx                        2.1.2
  sphinxcontrib-applehelp       1.0.1
  sphinxcontrib-devhelp         1.0.1
  sphinxcontrib-htmlhelp        1.0.2
  sphinxcontrib-jsmath          1.0.1
  sphinxcontrib-qthelp          1.0.2
  sphinxcontrib-serializinghtml 1.1.3
  spyder                        3.3.6
  spyder-kernels                0.5.1
  terminado                     0.8.2
  testpath                      0.4.2
  tornado                       6.0.3
  tqdm                          4.32.1
  traitlets                     4.3.2
  urllib3                       1.24.2
  wcwidth                       0.1.7
  webencodings                  0.5.1
  wheel                         0.33.4
  widgetsnbextension            3.5.0
  win-inet-pton                 1.1.0
  wincertstore                  0.2
  wrapt                         1.11.2
  </code></pre>
  
  <p><code>pip list</code> says scipy is version 1.3.1, while <code>conda list</code> says it's version 1.3.0. Again, not sure how relevant it is, but seems strange</p>
  
  <p>EDIT 3: I got this error after putting the following lines (suggested by @Brennan) in my command prompt then running the file</p>
  
  <pre><code>pip uninstall scikit-learn
  pip uninstall scipy
  conda uninstall scikit-learn
  conda uninstall scipy
  
  conda update --all
  conda install scipy
  conda install scikit-learn
  </code></pre>
  
  <p>This is the new error I get when trying to import sklearn:</p>
  
  <pre><code>Traceback (most recent call last):
  
    File "&lt;ipython-input-15-7135d3f24347&gt;", line 1, in &lt;module&gt;
      runfile('C:/Users/julia/.spyder-py3/temp.py', wdir='C:/Users/julia/.spyder-py3')
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
      execfile(filename, namespace)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
      exec(compile(f.read(), filename, 'exec'), namespace)
  
    File "C:/Users/julia/.spyder-py3/temp.py", line 2, in &lt;module&gt;
      import sklearn as skl
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\__init__.py", line 76, in &lt;module&gt;
      from .base import clone
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\base.py", line 13, in &lt;module&gt;
      import numpy as np
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in &lt;module&gt;
      from . import _distributor_init
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in &lt;module&gt;
      from . import _mklinit
  
  ImportError: DLL load failed: The specified module could not be found.
  </code></pre>
  
  <p>A possible cause of this might be me deleting the mkl_rt.dll file from my Anaconda/Library/bin after encountering the error described here: <a href="https://github.com/ContinuumIO/anaconda-issues/issues/10182" rel="nofollow noreferrer">https://github.com/ContinuumIO/anaconda-issues/issues/10182</a></p>
  
  <p>This puts me in a predicament, because reinstalling Anaconda to repair this will get me the same "ordinal 242 could not be located" error that I faced earlier, but not repairing it will continue the issue with sklearn...</p>
  
  <p><strong>FINAL EDIT: Solved by installing old version of Anaconda. Will mark as solved when I am able to (2 days)</strong></p>