title: Error: module not found in Jupyter Notebook (sklearn)
body: <p>I have an issue importing <code>scikit-learn</code> in my Jupyter notebooks, and I am at a loss as to why this is not working. I do not recall having this issue before with other packages. I have seen several threads with people having similar problems with this specific module, but none of the proposed checks have solved my problem, nor revealed to me what might be wrong. I have tried to add as much info as possible below, to try and figure out why this refuses to work.</p>
  
  <p>I use anaconda to manage my packages, and <code>scikit-learn</code> was installed as follows:</p>
  
  <pre><code>source activate python3
  conda install scikit-learn
  Fetching package metadata .............
  Solving package specifications: .
  
  # All requested packages already installed.
  # packages in environment at /Users/overaa/anaconda/envs/python3:
  #
  scikit-learn              0.19.1           py36hffbff8c_0  
  </code></pre>
  
  <p>Now, if I start a python session directly from the command line, <code>import sklearn</code> works as intended and the module is imported correctly. Doing the same in Jupyter results in </p>
  
  <p><code>ModuleNotFoundError: No module named 'sklearn'</code></p>
  
  <p>I have checked a number of things. First, making sure that my jupyter and jupyter-notebook point to the correct environment</p>
  
  <pre><code>which jupyter
  /Users/user_name/anaconda/envs/python3/bin/jupyter
  which jupyter-notebook
  /Users/user_name/anaconda/envs/python3/bin/jupyter-notebook
  </code></pre>
  
  <p>So the notebook checks out.</p>
  
  <p>Then from a command-line python session (in the same environment as where I launch my notebook):</p>
  
  <pre><code>&gt;&gt;&gt; import sklearn
  &gt;&gt;&gt; sklearn.__file__
  '/Users/user_name/anaconda/envs/python3/lib/python3.6/site_packages/sklearn/__init__.py'
  </code></pre>
  
  <p>So <code>scikit-learn</code> is also installed in the right environment. </p>
  
  <p>Now comparing that I am running the same version;</p>
  
  <p>From command line:</p>
  
  <pre><code>&gt;&gt;&gt; print(sys.version)
  3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:04:09)
  [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
  </code></pre>
  
  <p>From Jupyter notebook:</p>
  
  <pre><code>print(sys.version)
  3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:04:09
  [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
  </code></pre>
  
  <p>Comparing the packages path.</p>
  
  <p>From command line:</p>
  
  <pre><code>import site
  print(site.getsitepackages())
  ['/Users/user_name/anaconda/envs/python3/lib/python3.6/site-packages']
  </code></pre>
  
  <p>From Jupyter notebook:</p>
  
  <pre><code>import site
  print(site.getsitepackages())
  ['/Users/user_name/anaconda/envs/python3/lib/python3.6/site-packages']
  </code></pre>
  
  <p>Similarly for my <code>sys.path</code></p>
  
  <p>command line:</p>
  
  <pre><code>&gt;&gt;&gt; print(sys.path)
  ['', '/Users/user_name/anaconda/envs/python3/lib/python36.zip', 
  '/Users/user_name/anaconda/envs/python3/lib/python3.6', 
  '/Users/user_name/anaconda/envs/python3/lib/python3.6/lib-dynload', 
  '/Users/user_name/anaconda/envs/python3/lib/python3.6/site-packages', 
  '/Users/user_name/anaconda/envs/python3/lib/python3.6/site_packages/setuptools-27.2.0-py3.6.egg']
  </code></pre>
  
  <p>Jupyter:</p>
  
  <pre><code>print(sys.path)
  ['', '/Users/user_name/anaconda/envs/python36/lib/python36.zip', 
  '/Users/user_name/anaconda/envs/python36/lib/python3.6', 
  '/Users/user_name/anaconda/envs/python36/lib/python3.6/lib-dynload', 
  '/Users/user_name/anaconda/envs/python36/lib/python3.6/site-packages', 
  '/Users/user_name/anaconda/envs/python36/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg', 
  '/Users/user_name/anaconda/envs/python36/lib/python3.6/site-packages/IPython/extensions', 
  '/Users/user_name/.ipython']
  </code></pre>
  
  <p>So everything is the same, except that the directory containing the <code>setuptools</code> differ between the command-line version and the Jupyter version. I also noticed that <code>scikit-learn</code> seems to be installed in the <code>site_packages</code> subdir, rather than in the <code>site-packages</code> subdirectory, which is where Jupyter appear to be looking for modules. So I tried two things. First, adding the path to my <code>JUPYTER_PATH</code> in my .bash_profile before running my notebook.</p>
  
  <pre><code>export JUPYTER_PATH="/Users/user_name/anaconda/envs/python36/lib/python3.6/site-packages:$JUPYTER_PATH"
  </code></pre>
  
  <p>I also tried to add it to my <code>sys.path</code> directly in the jupyter notebook, prior to trying to import <code>scikit-learn</code></p>
  
  <pre><code>sys.path.append("/Users/user_name/anaconda/envs/python3/lib/python3.6/site_packages")
  </code></pre>
  
  <p>Both to no avail, <code>sklearn</code> still refuses to import in my notebook.</p>
  
  <p>Any ideas as to why <code>scikit-learn</code> is not getting imported into my Jupyter Notebook would be highly appreciated. Are there more things I can check? And how do I get this to work? </p>
  
  <p>I have tried activating/deactivating my environment, restart the kernels etc. also without success.</p>
  
  <p>EDIT: I have no problems importing other packages, like <code>numpy</code> or <code>scipy</code></p>