在 Jupyter 笔记本中更改解释器 [英] Change Interpreter in Jupyter notebook

查看:169
本文介绍了在 Jupyter 笔记本中更改解释器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的 Jupyter 笔记本环境的解释器路径更改为我与 PyCharm 一起使用的解释器路径.

I am trying to change the interpreter path of my Jupyter notebook environment to the interpreter path I am using with PyCharm.

当我使用 Jupyter notebook 执行以下代码时,我在 Anaconda 主文件夹中安装了 python,而不是我在 PyCharm 中使用的那个.

When I execute the following code with Jupyter notebook I am getting the python installation within the Anaconda main folder and not the one I am using with PyCharm.

import sys
print(sys.executable)

我可以使用哪个命令更改与 PyCharm 一起使用的其他 python 安装的路径?

With which command I can change the path to the other python installation I am using with PyCharm?

推荐答案

我相信您正在寻找的是如何更改您正在运行的内核.如果您转到 Jupyter 中的 Kernel 菜单,您将看到更改内核的选项.

I believe what you are looking for is how to change the Kernel you are running. If you go to the Kernel menu in Jupyter, you will see the option to change kernels.

如果要从 conda 环境添加新内核,请终止 jupyter,激活要为其添加内核的环境,然后运行此命令(需要 conda install ipykernel -- thx@shad):

If you want to add a new kernel from a conda environment, terminate jupyter, activate the environment you want to add a kernel for, and then run this command (requires conda install ipykernel -- thx @shad):

python -m ipykernel install --user --name <kernel_name> --display-name "<Name_to_display>"

确保将 替换为您的环境名称.此外,这需要您conda install ipykernel(感谢@shad).

Make sure to replace <kernel_name> and <Name_to_display> to the name of your environment. Also, this requires you to conda install ipykernel (thanks @shad).

安装内核后,您可以通过上面的菜单甚至通过 Jupyter 单元中的以下代码片段更改它:

Once you installed the kernel, you can change to it through the above menu and even through this code snippet from a Jupyter cell:

%%javascript
Jupyter.notebook.session.restart({kernel_name: '<kernel_name>'})

这篇关于在 Jupyter 笔记本中更改解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆