1

So I set up my virtual lan with python 3 and jupyter (with pip). All works fine but if I try to import keras it will not work in jupyter and tells module not found. But if I execute the same file (python3 test.py) in the terminal it works fine.

which jupyter
/usr/local/bin/jupyter

which python3
/Users/niro273/Desktop/xcorp/bin/python3

If I do a pip3 list these are the results.

jupyter (1.0.0)
jupyter-client (5.1.0)
jupyter-console (5.2.0)
jupyter-core (4.3.0)
Keras (2.0.8)

Note- I have installed jupyter (pip3 install jupyter) inside the virtual env too. So should I have to switch the juypter execution path ? Would appreciate any guidance.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Nirojan Selvanathan
  • 10,066
  • 5
  • 61
  • 82

2 Answers2

5

Both Keras & Jupyter must be installed inside your virtual environment; then, you should start Jupyter after activating your virtual env (in which case which jupyter should point to a different location inside your virtual env):

$ which jupyter
/usr/local/bin/jupyter
$ virtualenv /venv/foo
$ source /venv/foo/bin/activate
$ (foo) pip3 install jupyter
$ (foo) which jupyter
/venv/foo/bin/jupyter
$ (foo) pip3 install keras
$ (foo) jupyter notebook

There are certainly other ways (e.g. to install a different kernel in your main Jupyter installation pointing to the Python executable in your foo virtual environment), but I have found the above way to be quicker and more hassle-free, at least for Keras...

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • Tried this previously. The problem is although I install jupyter inside virtual lan the which jupyter results remains the same. Getting some thing like this "Requirement already satisfied: jupyter in /usr/local/lib/python3.6/site-packages" if I try to reinstall – Nirojan Selvanathan Aug 29 '17 at 13:52
  • 1
    OK, let's try the other way - can you please share the results of the command `jupyter kernelspec list`? – desertnaut Aug 29 '17 at 13:56
  • 1
    Oh , now figured out what happened. I have used this command to create the virtual env. "virtualenv --system-site-packages -p python3". So this sites the global packages it seems. Thanks for guidance. :) – Nirojan Selvanathan Aug 29 '17 at 13:59
0

For Windows Users

I had the same issue on Windows 10 @desertnaut's answer really helped.

1 Activate the virtual environment.

2 Then pip install jupyter.

3 Then you are all set.

Michael Yadidya
  • 1,397
  • 1
  • 9
  • 15