问题描述
我正在使用 Anaconda 来管理 Python 和 Jupyter.那就是:
I'm using Anaconda to manage both Python and Jupyter. That is:
>> which python
>> /home/.../software/anaconda3/bin/python
和
>> which jupyter
>> /home/.../software/anaconda3/bin/jupyter
但是 Jupyter 的 python 内核似乎通过 Anaconda 指向 Python 的系统版本,而不是我的本地版本,因为 sys.path
在 Jupyter Python 3 笔记本中是不同的.此外,jupyter kernelspec list
给出以下内容:
But Jupyter's python kernel seems to be pointing to a system version of Python rather than my local version through Anaconda, since the sys.path
is different in a Jupyter Python 3 notebook. Also, jupyter kernelspec list
gives the following:
Available kernels:
ir /usr/local/share/jupyter/kernels/ir
matlab /usr/local/share/jupyter/kernels/matlab
python3 /usr/local/share/jupyter/kernels/python3
这似乎并不令人惊讶,因为 docs 在第 1.5.5 节:
This doesn't seem altogether surprising since the docs say in section 1.5.5:
默认情况下,内核规范将位于系统范围的位置(例如/usr/local/share/jupyter/kernels).如果执行 --user 安装,内核规范将位于 JUPYTER_DATA_DIR 位置.
为了个人的理智和组织,我希望我在命令行中使用的 Python 版本与在 Jupyter 中访问的版本相同.结果,我认为我应该做的是更改 python3 的 jupyter kernelspec 列表,使其指向我想要的 Anaconda python 版本,即 /home/.../software/anaconda3/bin/python
.我的问题是:1)这确实是我陈述的偏好的最佳解决方案,以及 2)我如何实际更改 python3 的 jupyter kernelspec 条目?不确定这是否会出现,但我不想使用虚拟环境——我希望命令行和 Jupyter 的默认 Python 版本相同.
For personal sanity and organization, I want the version of Python that I use in the command line to be the same that is accessed in Jupyter. As a result, I think that what I should do is change my jupyter kernelspec list for python3 so that it points to my desired Anaconda python version, i.e. /home/.../software/anaconda3/bin/python
. My questions are: 1) is that indeed the best solution for my stated preferences, and 2) how do I actually change my jupyter kernelspec entry for python3? Not sure if this will come up, but I don't want to be using virtual environments--I want the default to be same version of Python across both the command line and Jupyter.
推荐答案
我把这个转发到 Jupyter Github 问题页面,建议删除 /usr/local/share/jupyter/kernels/python3.这允许 Jupyter 使用运行 Jupyter 本身的相同 Python(即 Anaconda)找到默认的 Python 内核,这对我有用.
I ended up reposting this to the Jupyter Github issues page, and was recommended to delete
/usr/local/share/jupyter/kernels/python3
. This allows Jupyter to find a default Python kernel using the same Python running Jupyter itself (i.e. Anaconda), and this worked for me.
您可以在 Jupyter 的 Github 页面上找到我的帖子以及上述解决方案为何有效的解释 这里.
You can find my post on Jupyter's Github page as well as an explanation for why the above solution works here.
这篇关于将 Jupyter kernelspec 更改为指向 anaconda python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!