title: Running Tensorflow in Jupyter Notebook
body: <p>I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment. </p>
  
  <p>Here is what I did. </p>
  
  <p>In Anaconda, I created an environment called <code>tensorflow</code> as follows</p>
  
  <pre><code>conda create -n tensorflow
  </code></pre>
  
  <p>Then installed the data science Python packages, like Pandas, NumPy, etc., inside it. I also installed TensorFlow and Keras there. Here is the list of packages in that environment</p>
  
  <pre><code>(tensorflow) SFOM00618927A:dl i854319$ conda list
  # packages in environment at /Users/i854319/anaconda/envs/tensorflow:
  #
  appdirs                   1.4.3                     &lt;pip&gt;
  appnope                   0.1.0                    py36_0  
  beautifulsoup4            4.5.3                    py36_0  
  bleach                    1.5.0                    py36_0  
  cycler                    0.10.0                   py36_0  
  decorator                 4.0.11                   py36_0  
  entrypoints               0.2.2                    py36_1  
  freetype                  2.5.5                         2  
  html5lib                  0.999                    py36_0  
  icu                       54.1                          0  
  ipykernel                 4.5.2                    py36_0  
  ipython                   5.3.0                    py36_0  
  ipython_genutils          0.2.0                    py36_0  
  ipywidgets                6.0.0                    py36_0  
  jinja2                    2.9.5                    py36_0  
  jsonschema                2.5.1                    py36_0  
  jupyter                   1.0.0                    py36_3  
  jupyter_client            5.0.0                    py36_0  
  jupyter_console           5.1.0                    py36_0  
  jupyter_core              4.3.0                    py36_0  
  Keras                     2.0.2                     &lt;pip&gt;
  libpng                    1.6.27                        0  
  markupsafe                0.23                     py36_2  
  matplotlib                2.0.0               np112py36_0  
  mistune                   0.7.4                    py36_0  
  mkl                       2017.0.1                      0  
  nbconvert                 5.1.1                    py36_0  
  nbformat                  4.3.0                    py36_0  
  notebook                  4.4.1                    py36_0  
  numpy                     1.12.1                    &lt;pip&gt;
  numpy                     1.12.1                   py36_0  
  openssl                   1.0.2k                        1  
  packaging                 16.8                      &lt;pip&gt;
  pandas                    0.19.2              np112py36_1  
  pandocfilters             1.4.1                    py36_0  
  path.py                   10.1                     py36_0  
  pexpect                   4.2.1                    py36_0  
  pickleshare               0.7.4                    py36_0  
  pip                       9.0.1                    py36_1  
  prompt_toolkit            1.0.13                   py36_0  
  protobuf                  3.2.0                     &lt;pip&gt;
  ptyprocess                0.5.1                    py36_0  
  pygments                  2.2.0                    py36_0  
  pyparsing                 2.1.4                    py36_0  
  pyparsing                 2.2.0                     &lt;pip&gt;
  pyqt                      5.6.0                    py36_2  
  python                    3.6.1                         0  
  python-dateutil           2.6.0                    py36_0  
  pytz                      2017.2                   py36_0  
  PyYAML                    3.12                      &lt;pip&gt;
  pyzmq                     16.0.2                   py36_0  
  qt                        5.6.2                         0  
  qtconsole                 4.3.0                    py36_0  
  readline                  6.2                           2  
  scikit-learn              0.18.1              np112py36_1  
  scipy                     0.19.0              np112py36_0  
  setuptools                34.3.3                    &lt;pip&gt;
  setuptools                27.2.0                   py36_0  
  simplegeneric             0.8.1                    py36_1  
  sip                       4.18                     py36_0  
  six                       1.10.0                    &lt;pip&gt;
  six                       1.10.0                   py36_0  
  sqlite                    3.13.0                        0  
  tensorflow                1.0.1                     &lt;pip&gt;
  terminado                 0.6                      py36_0  
  testpath                  0.3                      py36_0  
  Theano                    0.9.0                     &lt;pip&gt;
  tk                        8.5.18                        0  
  tornado                   4.4.2                    py36_0  
  traitlets                 4.3.2                    py36_0  
  wcwidth                   0.1.7                    py36_0  
  wheel                     0.29.0                    &lt;pip&gt;
  wheel                     0.29.0                   py36_0  
  widgetsnbextension        2.0.0                    py36_0  
  xz                        5.2.2                         1  
  zlib                      1.2.8                         3  
  (tensorflow) SFOM00618927A:dl i854319$
  </code></pre>
  
  <p>You can see that <code>jupyter</code> is also installed.</p>
  
  <p>Now, when I open up the Python interpreter in this environment and I run the basic TensorFlow command, it all works fine.  However, I wanted to do the same thing in the Jupyter notebook. So, I created a new directory (outside of this environment). </p>
  
  <pre><code>mkdir dl
  </code></pre>
  
  <p>In that, I activated <code>tensorflow</code> environment</p>
  
  <pre><code>SFOM00618927A:dl i854319$ source activate tensorflow
  (tensorflow) SFOM00618927A:dl i854319$ conda list
  </code></pre>
  
  <p>And I can see the same list of packages in that. </p>
  
  <p>Now, I open up a Jupyter notebook</p>
  
  <pre><code>SFOM00618927A:dl i854319$ source activate tensorflow
  (tensorflow) SFOM00618927A:dl i854319$ jupyter notebook
  </code></pre>
  
  <p>It opens up a new notebook in the browser. But when I just import basic python libraries in that, like pandas, it says "no packages available". I am not sure why is that when the same environment has all those packages and in the same directory, if I use Python interpreter it shows all packages. </p>
  
  <pre><code>import pandas
  ---------------------------------------------------------------------------
  ModuleNotFoundError                       Traceback (most recent call last)
  &lt;ipython-input-4-d6ac987968b6&gt; in &lt;module&gt;()
  ----&gt; 1 import pandas
  
  ModuleNotFoundError: No module named 'pandas'
  </code></pre>
  
  <p>Why jupyter notebook is not picking up these modules?</p>
  
  <p>So, Jupyter notebook doesn't show env as the interpreter </p>
  
  <p><a href="https://i.stack.imgur.com/whyaq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/whyaq.png" alt="enter image description here"></a></p>