我安装了Anaconda的Python 3,并希望能够在python2和3内核之间快速切换。这是在OSX上。
到目前为止,我的步骤涉及:
conda create -p ~/anaconda/envs/python2 python=2.7
source activate python2
conda install ipython
ipython kernelspec install-self
source deactivate
之后,我可以在python3 IPython笔记本中选择一个python2内核,但是该笔记本无法启动。
所以我继续修改了/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/"}
}
现在,当我启动python2内核时,它失败并显示:
ImportError: No module named site
显然,IPython需要显式的路径名,因此没有'〜'而不是主目录。将kernel.json更改为:
{
"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"}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句