Scikit-learn fails to import only in Jupyter notebook
<p>I have Anaconda installed on OS X.  I am able to import sklearn from a python terminal and an IPython terminal.  But when I try to import sklearn from a Jupyter notebook, I get the following error:</p>

<pre><code>---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
&lt;ipython-input-4-8fd979e02004&gt; in &lt;module&gt;()
----&gt; 1 import sklearn

/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/__init__.py in &lt;module&gt;()
     55 else:
     56     from . import __check_build
---&gt; 57     from .base import clone
     58     __check_build  # avoid flakes unused variable error
     59 

/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/base.py in &lt;module&gt;()
     10 from scipy import sparse
     11 from .externals import six
---&gt; 12 from .utils.fixes import signature
     13 from .utils.deprecation import deprecated
     14 from .exceptions import ChangedBehaviorWarning as _ChangedBehaviorWarning

/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/utils/__init__.py in &lt;module&gt;()
      9 
     10 from .murmurhash import murmurhash3_32
---&gt; 11 from .validation import (as_float_array,
     12                          assert_all_finite,
     13                          check_random_state, column_or_1d, check_array,

/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/utils/validation.py in &lt;module&gt;()
     16 
     17 from ..externals import six
---&gt; 18 from ..utils.fixes import signature
     19 from .deprecation import deprecated
     20 from ..exceptions import DataConversionWarning as _DataConversionWarning

/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/utils/fixes.py in &lt;module&gt;()
    288     from ._scipy_sparse_lsqr_backport import lsqr as sparse_lsqr
    289 else:
--&gt; 290     from scipy.sparse.linalg import lsqr as sparse_lsqr
    291 
    292 

/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/__init__.py in &lt;module&gt;()
    110 from __future__ import division, print_function, absolute_import
    111 
--&gt; 112 from .isolve import *
    113 from .dsolve import *
    114 from .interface import *

/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/__init__.py in &lt;module&gt;()
      4 
      5 #from info import __doc__
----&gt; 6 from .iterative import *
      7 from .minres import minres
      8 from .lgmres import lgmres

/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/iterative.py in &lt;module&gt;()
      5 __all__ = ['bicg','bicgstab','cg','cgs','gmres','qmr']
      6 
----&gt; 7 from . import _iterative
      8 
      9 from scipy.sparse.linalg.interface import LinearOperator

ImportError: dlopen(/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/_iterative.so, 2): Library not loaded: /usr/local/lib/libgcc_s.1.dylib
  Referenced from: /Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/_iterative.so
  Reason: image not found
</code></pre>

<p>I can import numpy, scipy, and pandas fine from the Jupyter notebook.  It is just sklearn that fails.</p>

<p>I have also tried creating a new conda environment (<code>conda create -n test_env jupyter notebook matplotlib scipy numpy pandas scikit-learn</code>), but the error persists in the new environment as well.</p>

<p>I managed to figure out what was going on, so I'll post my solution here in case anyone else runs into the same problem.  As it turns out, I had modified the <code>DYLD_FALLBACK_LIBRARY_PATH</code> environment variable in my <code>.bashrc</code> file when I had installed another piece of software.  Restoring this environment variable to its default fixed the problem for me.</p>

<p>(Incidentally, scikit-learn was failing to import in a standard Python terminal as well.  I didn't initially realize this because I was testing the Python terminal in an environment in which I had accidentally restored the environment variables to their defaults, overwriting the change I had made in my <code>.bashrc</code> file.)</p>

python scikit-learn importerror jupyter-notebook