I would like to configure jupyter to allow me to run python 2.7 and 3.4 kernels at the same time side-by-side in two different notebooks (or maybe even switch from one to the other in a single notebook).
(1) Is this possible?
I am asking since it was suggested in Using both Python 2.x and Python 3.x in IPython Notebook that this would be possible, but no elaborate answer was provided on how exactly this would work.
You can also see in https://try.jupyter.org that it somehow appears to be very much feasible (and you can even switch from one python 2 kernel to a python 3 kernel). So I find it reasonable to assume that it is indeed possible (but please correct me if I am wrong).
(2) How is this done?
Previous answers (e.g. in Open IPython Notebook 2.7 and 3.4 in Parallel) recommend starting two different ipython notebook servers at two different ports. This, of course, is entirely logical and possible, but does NOT answer my question.
I managed to install ipython
for python 2 & 3. I then got both kernels to show up in jupyter
by calling the following in each respective python environment:
ipython kernelspec install-self
This created kernel.json
files for me and I could now select either of them to create a new notebook in jupyter
. Example of kernel.json
for python 2:
{
"display_name": "Python 2",
"language": "python",
"argv": [
"/usr/local/opt/python/bin/python2.7",
"-m",
"ipykernel",
"-f",
"{connection_file}"
]
}
The problem is, when I start jupyter
from a python 2 environment (with $PYTHONPATH
defined), I can only run a python 2 kernel (the other one will crash when opening the corresponding notebook). The same, when I start jupyter
from a python 3 environment (with $PYTHONPATH
defined). This generally makes sense to me, but I would like to know how to start or configure jupyter
to allow both kernels to be run from the same jupyter
instance and still specify my own specific $PYTHONPATH
s to be able to load my packages.
I figured that this is my actual problem - predefining $PYTHONPATH
before I start jupyter
. So I called:
unset PYTHONPATH
ipython notebook
I can now indeed run both kernels (py2&3) from a single jupyter
instance, but I can't load python packages from specific local directories. I guess I could do this manually inside the notebook with:
import sys
sys.path.append("/some/path/lib/python2.7/site-packages")
but is this really the way I should be doing it? or can I configure additional directories I normally write into $PYTHONPATH
somewhere else (e.g. that kernel.json
file?
PS: Please don't ask why I need this - no, I don't really need it - but I still would like to know if and how this might be possible.
[EDIT]
Please note that I would not be comfortable installing some python management utility (such as Anaconda) to accomplish all of this, (unless it is the only way).