I have a Python 3 installation of Anaconda and want to be able to switch quickly between python2 and 3 kernels. This is on OSX.
My steps so far involved:
conda create -p ~/anaconda/envs/python2 python=2.7
source activate python2
conda install ipython
ipython kernelspec install-self
source deactivate
After this I have a python2 Kernel to choose from in the python3 IPython notebook, which however can't start.
So I went ahead and modified /usr/local/share/jupyter/kernels/python2/kernel.json
{
"display_name": "Python 2",
"language": "python",
"argv": [
"/Users/sonium/anaconda/envs/python2/bin/python",
"-m",
"IPython.kernel",
"-f",
"{connection_file}"
],
"env":{"PYTHONHOME":"~/anaconda/envs/python2/:~/anaconda/envs/python2/lib/"}
}
Now when I start the python2 kernel it fails with:
ImportError: No module named site
Apparently IPython expects explicit pathnames, so no '~' instead of the home directory. It worked after changing the kernel.json to:
{
"display_name": "Python 2",
"language": "python",
"argv": [
"/Users/sonium/anaconda/envs/python2/bin/python2.7",
"-m",
"IPython.kernel",
"-f",
"{connection_file}"
],
"env":{"PYTHONHOME":"/Users/sonium/anaconda/envs/python2"}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments