6

I had installed tensorflow with pip install, and installed keras with conda install: (my python3 is installed under Anaconda3)

conda create -n keras python=3.5 activate keras pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.1-cp35-cp35m-win_amd64.whl conda install --channel https://conda.anaconda.org/conda-forge keras 

Now when I run the following commands in commandline, everything works fine:

activate keras python import tensorflow import keras from keras.datasets import mnist 

However, when I run the same commands with jupyter, I get an error on the keras import line:

activate keras jupyter notebook # now open a python3 notebook # and enter the above commands in it # and run ImportError: No module named 'keras' 

However the import for tensorflow gives no error.

I then uninstalled tensorflow, and reinstalled it with conda install:

conda install tensorflow 

Now when I run jupyter, I get the same error on the tensorflow line also.

How can I get jupyter to work on packages installed with conda?

Additional information: I ran sys.executable both from commandline and jupyter, and both point to the same path:

'C:\\sw\\Anaconda3\\envs\\tensorflow\\python.exe' 

It looks like a recent problem, I found a similar report at https://github.com/jupyter/jupyter/issues/245, But I did not quite understand the solution. Can anyone help here?

5
  • 2
    It seems jupyter is not using the same python installation or it has a different package folder. In other words, keras is not installed on the python package than you have jupyter. Commented Aug 15, 2017 at 13:31
  • Usually this indicates that the notebook is running with a different Python or in a different environment from Python in the command prompt. Check sys.executable to see which Python executable itis is using, and sys.path to see where it's looking for imports Commented Aug 15, 2017 at 13:32
  • It is also possible that you installed keras on python2, and now you want to run it on python 3. Commented Aug 15, 2017 at 13:42
  • I have now provided answers to these comments by giving additional information in the question. Please see that. Commented Aug 15, 2017 at 14:30
  • After some debugging, I found that any package installed with conda does not work in jupyter. So I changed the question title and simplified my question. Commented Aug 15, 2017 at 16:39

2 Answers 2

5

I found the answer at http://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environments

ipykernel has to be linked to the environment, and then jupyter can use it.

The following installation procedure works:

conda create -n keras python=3.5 ipykernel activate keras python -m ipykernel install --user --name keras jupyter notebook 

Now if I call sys.executable in the jupyter notebook, it prints the correct environment from where the executables are accessed.

Sign up to request clarification or add additional context in comments.

Comments

1

install jupyter in your environment:

activate keras conda install jupyter 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.