gpt4 book ai didi

python - python : Python 3 and 2 in IPython/Jupyter Notebook

转载 作者:太空狗 更新时间:2023-10-29 21:05:38 26 4
gpt4 key购买 nike

我安装了 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 notebook 中有一个 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"}
}

关于python - python : Python 3 and 2 in IPython/Jupyter Notebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29648412/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com