简体   繁体   English

在 Jupyter 笔记本中更改解释器

[英]Change Interpreter in Jupyter notebook

I am trying to change the interpreter path of my Jupyter notebook environment to the interpreter path I am using with PyCharm.我正在尝试将 Jupyter 笔记本环境的解释器路径更改为与 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.当我使用 Jupyter 笔记本执行以下代码时,我在 Anaconda 主文件夹中安装了 python,而不是我与 PyCharm 一起使用的那个。

import sys
print(sys.executable)

With which command I can change the path to the other python installation I am using with PyCharm?使用哪个命令,我可以更改与 PyCharm 一起使用的其他 python 安装的路径?

I believe what you are looking for is how to change the Kernel you are running.我相信您正在寻找的是如何更改您正在运行的 Kernel。 If you go to the Kernel menu in Jupyter, you will see the option to change kernels.如果您将 go 转到 Jupyter 中的 Kernel 菜单,您将看到更改内核的选项。

在此处输入图像描述

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):如果要从 conda 环境添加新的 kernel,请终止 jupyter,激活要为其添加 kernel 的环境,然后运行此命令(需要conda install ipykernel -- thx @shad):

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

Make sure to replace <kernel_name> and <Name_to_display> to the name of your environment.确保将<kernel_name><Name_to_display>替换为您的环境名称。 Also, this requires you to conda install ipykernel (thanks @shad).此外,这需要您conda install ipykernel (感谢@shad)。

Once you installed the kernel, you can change to it through the above menu and even through this code snippet from a Jupyter cell:安装 kernel 后,您可以通过上面的菜单甚至通过 Jupyter 单元中的以下代码片段进行更改:

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

Activate first the env you want to use:首先激活您要使用的环境:

conda activate myenv

Then start jupyter afterwards:然后启动jupyter:

jupyter notebook /path/to/your/dir

You can also use the following:您还可以使用以下内容:

conda activate base 

then check the location of the jupyter using然后使用检查jupyter的位置

type jupyter

if it is located in如果它位于

~/anaconda3/bin/jupyter ~/anaconda3/bin/jupyter

then you are good to go.那么你对 go 很好。 After that, you can use the jupyter The one I use with my ssh-tunneling between my host and server machines is:之后,您可以使用jupyter我在主机和服务器机器之间的 ssh 隧道中使用的是:

jupyter notebook --no-browser --port=1234

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM