1

I had started with udacity deep learning course and was setting up environments. I think the kernel notebook uses does not use python from conda environment. Following are some of the results of things I have tried.

Started conda environment

source activate tensorflow

With python terminal inside conda environment from linux terminal:

import sys
sys.executable
>>> '/home/username/anaconda2/envs/tensorflow/bin/python' 

Also tensorflow gets imported with python shell

With ipython terminal inside conda environment, it shows same executable path. and tensorflow gets imported inside ipython shell.

However with jupyter notebook when I execute a cell in notebook, tensorflow module cannot be found. Also terminal spawned from notebook shows executable path of global python installation which is in anaconda/bin directoty, not of environment I had created from which I started the notebook

'/home/username/anaconda2/bin/python'

However conda environment of shell is still tensorflow

conda info --envs
# conda environments:                                                                                                              
#                                                                                                                                  
tensorflow            *  /home/username/anaconda2/envs/tensorflow                                                                     
root                     /home/username/anaconda2

Does that mean kernel is linked to python installation in this location and not in conda env? How to link the same?

pratsJ
  • 3,369
  • 3
  • 22
  • 41
  • 1
    In order to use the tensorflow environment in jupyter, you also have to register an ipython kernel in your tensorflow environment. You can take my answer here as a guide: http://stackoverflow.com/questions/30492623/using-both-python-2-x-and-python-3-x-in-ipython-notebook/30492913#30492913 – cel Sep 10 '16 at 08:16
  • @cel Great! it worked. Thanks. – pratsJ Sep 10 '16 at 08:41

1 Answers1

1

There is some more nuance to this question that is good to clarify. Each notebook is bound to a particular kernel. With the latest 4.0 release of Anaconda we (Continuum) have bundled a Conda-environment-aware extension that will try to associate a Notebook with a particular Conda environment. If that cannot be found then the "default" environment (or "root" environment) will be used. In your case you have a Notebook that is, I am guessing, asking for the default (or "root") environment, and so Jupyter starts a kernel in that environment, and not in the environment from which the Jupyter server was started. You can change the associated kernel by going to the Kernel->Change kernel menu and picking your tensorflow environment's kernel, along the lines of this:

enter image description here

Or when you create a new Notebook you can pick at that time which Conda environment's kernel should back the Notebook (note that one Conda environment can have multiple kernels available, e.g. Python and R):

enter image description here

We appreciate that this can be a common cause of confusion, especially when sharing notebooks, since the person who shared it either used the "default" kernel (probably called just "Python"), or they were using a Conda environment with a different name. We are working on ways to make this smoother and less confusing, but if you have suggestions for expected/desired behavior, please let us know (GitHub issue to https://github.com/ContinuumIO/anaconda-issues/issues/new is the best way to do this)

IanSR
  • 9,898
  • 4
  • 14
  • 15
  • 1
    I very recently started using conda environment for development so am not very aware of relationship between notebook, python and kernel and how it works with environment. Would have been helpful if there is short introduction to basics and how all this is connected. – pratsJ Sep 13 '16 at 15:51