1
votes

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?

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: stackoverflow.com/questions/30492623/…cel
@cel Great! it worked. Thanks.pratsJ

1 Answers

1
votes

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)