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"}
}
I install the Anaconda 3 in Win10. I am now focus on python 3, but I have lot projects written in python 2. If I want check them in juypter in python environment it's will failed, and shows "kernel error". The solution is almost like above, but something different.
The path to find those two json files is :
C:\ProgramData\jupyter\kernels
Sometime it may be hidden.
Another path you need check, after you create a python2 environment in Anaconda, try to find this path:
C:\Users\username\Anaconda3\envs\python2\python.exe
Copy it to your python2 kernel json file then it should be work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With