# 管理 Jupyter notebook 服务器

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com.cn/help/idea/llms.txt).

> **Warning:**
> 以下内容仅在 Python 和 Jupyter 插件 [已安装并启用](managing-plugins.html)时有效！

在 IntelliJ IDEA 中，您可以使用以下类型的服务器执行代码单元：

* 托管服务器 – 当前项目的 IntelliJ IDEA 自动启动的 Jupyter 服务器。 当您关闭 IntelliJ IDEA 时，它将被终止。

* 外部服务器 ——任何通过指定其 URL 和 token 连接的 Jupyter 服务器。 它可以运行在本地或远程机器上。

> **Note:**
> Jupyter 服务器连接设置是特定用户的。

## 添加托管 Jupyter 服务器

Procedure:

1. 转到  `工具 | 添加 Jupyter 连接...`

或者，右键点击项目目录，并从上下文菜单中选择  `新建 | Jupyter 连接` 。

2. 在打开的窗口中，点击 ![添加 Jupyter 连接](https://resources.jetbrains.com.cn/help/img/idea/2026.3/app.expui.general.add.svg)   添加配置  ，或按 `Alt+Insert` (Windows), `⌘ N` (macOS), `⌃ N` (IntelliJ IDEA Classic (macOS)), `⌘ N` (macOS System Shortcuts), `Alt+Insert` (XWin), `Alt+Insert` (GNOME), `Alt+Insert` (KDE), `Alt+Insert` (Emacs), `Ctrl+N` (Sublime Text), `⌘ N` (Sublime Text (macOS)), `Ctrl+N` (Visual Studio), `⌘ N` (Visual Studio (macOS)), `Alt+Insert` (NetBeans), `Alt+Insert` (Eclipse), `⌘ N` (Eclipse (macOS)) 并选择   IDE 托管服务器  。

有关配置托管服务器的更多信息，请参阅 [设置托管服务器](#setup-managed-server)。

3. 如果您希望新创建的服务器自动为当前笔记本选择，请点击   OK  。

![添加托管服务器](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_add_jupyter_managed_server.png)

## 添加外部 Jupyter 服务器

Procedure:

1. 转到  `工具 | 添加 Jupyter 连接...`

或者，右键点击项目目录，并从上下文菜单中选择  `新建 | Jupyter 连接` 。

2. 在打开的窗口中，点击 ![添加 Jupyter 连接](https://resources.jetbrains.com.cn/help/img/idea/2026.3/app.expui.general.add.svg)   添加配置  ，或按 `Alt+Insert` (Windows), `⌘ N` (macOS), `⌃ N` (IntelliJ IDEA Classic (macOS)), `⌘ N` (macOS System Shortcuts), `Alt+Insert` (XWin), `Alt+Insert` (GNOME), `Alt+Insert` (KDE), `Alt+Insert` (Emacs), `Ctrl+N` (Sublime Text), `⌘ N` (Sublime Text (macOS)), `Ctrl+N` (Visual Studio), `⌘ N` (Visual Studio (macOS)), `Alt+Insert` (NetBeans), `Alt+Insert` (Eclipse), `⌘ N` (Eclipse (macOS)) 并选择   外部服务器  。

有关配置外部服务器的更多信息，请参阅 [设置外部服务器](#setup-configured-server)。

3. 如果您希望新创建的服务器自动为当前笔记本选择，请点击   OK  。

> **Tip:**
> 添加的已配置服务器显示在 [Project View](project-tool-window.html#views) 中。
>
> ![Project View 面板中的远程服务器](https://resources.jetbrains.com.cn/help/img/idea/2026.3/ij_remote_server_in_project_view.png)

## 设置托管服务器

Procedure:

1. 点击 [Jupyter 笔记本工具栏](jupyter-notebook-support.html#toolbar) 上的服务器列表，并从上下文菜单中选择   配置 Jupyter 服务器  。

![配置 Jupyter 服务器](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_configure_jupyter_server.png)

2. 在打开的窗口中，选择   托管服务器  。

托管服务器会自动选择 Jupyter Notebook 的执行方法。 要手动配置服务器设置，请清除  `自动检测的执行模式`  复选框。

3. 选择执行模式：

JupyterLab:

* 使用 命令行参数 字段设置服务器设置。

* 设置 环境变量 并为其分配值。

* Jupyter 服务器可以通过令牌（包含在 URL 中）或用户定义的密码进行保护。 如果 Jupyter 服务器通过密码保护，请在 密码 字段中输入密码。 有关更多信息，请参阅 [Jupyter 笔记本服务器中的安全性](https://jupyter-notebook.readthedocs.io/en/v6.5.2/security.html#security-in-the-jupyter-notebook-server)。

IPyKernel 内核:

IPython 内核已可使用，无需额外设置。

> **Note:**
> IPyKernel 仅支持 Python 笔记本，且对于该类型的内核，不提供   在浏览器中打开 Notebook   选项

4. 单击   OK   以应用更改并关闭窗口。

> **Note:**
> 托管服务器将显示在 [Jupyter 笔记本工具栏](jupyter-notebook-support.html#toolbar) 上的服务器列表中。

## 设置外部服务器

Procedure:

1. 点击 [Jupyter 笔记本工具栏](jupyter-notebook-support.html#toolbar) 上的服务器列表，并从上下文菜单中选择   配置 Jupyter 服务器  。

![配置 Jupyter 服务器](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_configure_jupyter_server.png)

或者，在 Project View 中右键点击服务器 `Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Ctrl+1` (NetBeans), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS)) 并从上下文菜单中选择  `配置 Jupyter 服务器` 。

2. 在打开的窗口中，选择要配置的外部服务器。

3. 在   名称   字段中，设置外部服务器的名称。

4. 在   服务器 URL   字段中，指定用于建立与外部 Jupyter 服务器连接的地址。 目标 URL 应包含服务器名称或其地址及访问令牌。

要在本机上自动检测可用的 Jupyter 实例，请单击   发现本地服务器  。 如果找到服务器，URL 和令牌将自动填充。

> **Tip:**
> 要查找外部服务器的令牌，您可以在终端中运行  `jupyter server list`  或  `jupyter lab list`  命令

5. 在   类型   下，选择所需的服务器类型。

Notebook/Lab:

使用此选项连接到本地或远程机器上运行的标准   Jupyter 笔记本   或   JupyterLab   实例。

提供所需的身份验证令牌或密码。

![Notebook/Lab](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_jupyter_server_notebook_lab.png)

> **Note:**
> 如果您将字段留空，令牌将从 URI 中提取。

Hub:

使用此选项连接到   JupyterHub   实例。

提供以下之一：

* 您的用户名、密码和 Hub 的 URL（如果通过登录凭据进行身份验证）。

* 包含访问令牌的运行中 Jupyter 笔记本服务器的直接 URL（如果使用基于令牌的身份验证）。

![Hub](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_jupyter_server_hub.png)

AWS SageMaker:

使用此选项连接到   AWS SageMaker   实例或其他云解决方案。

无需令牌，您可以直接使用预签名的 URL。

![AWS SageMaker](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_jupyter_server_aws.png)

6. 如果服务器需要代理连接，请选中   使用 IDE 代理   复选框。

请参阅 [HTTP 代理](settings-http-proxy.html) 页面以配置相应设置。

7. 点击   测试连接   验证设置。

8. 单击   OK   以应用更改并关闭窗口。

## 管理外部服务器文件

Procedure:

连接外部 Jupyter 服务器后，其文件会显示在 [项目视图](project-tool-window.html#views) 中。 可以像操作本地项目中的文件一样，创建、打开、编辑和删除外部 Jupyter 服务器中的文件。 例如：

* 要添加文件，请右键点击外部服务器目录或其中的软件包，并从上下文菜单中选择 新建 。 选择所需的文件类型。 有关更多信息，请参见 [创建新项](add-items-to-project.html#create-new-items)。 ![添加远程服务器文件](https://resources.jetbrains.com.cn/help/img/idea/2026.3/ij_add_remote_server_file.png)

* 要删除文件，请在外部服务器目录中右键点击该文件，并从上下文菜单中选择 删除 `Delete` (Windows), `⌦` (macOS), `⌦` (IntelliJ IDEA Classic (macOS)), `⌦` (macOS System Shortcuts), `Delete` (XWin), `Delete` (GNOME), `Delete` (KDE), `Delete` (Emacs), `Delete` (Sublime Text), `⌦` (Sublime Text (macOS)), `Delete` (Visual Studio), `⌦` (Visual Studio (macOS)), `Delete` (NetBeans), `Delete` (Eclipse), `⌦` (Eclipse (macOS))。 ![删除远程服务器文件](https://resources.jetbrains.com.cn/help/img/idea/2026.3/ij_delete_remote_server_file.png)

## 移除 Jupyter 服务器

Procedure:

* 转到  `设置 | 工具 | Jupyter | Jupyter 服务器` 。

在打开的窗口中，选择您要移除的服务器，然后点击 ![移除配置](https://resources.jetbrains.com.cn/help/img/idea/2026.3/app-client.expui.general.remove.svg)   移除配置   或按 `Delete` (Windows), `⌦` (macOS), `⌦` (IntelliJ IDEA Classic (macOS)), `⌦` (macOS System Shortcuts), `Delete` (XWin), `Delete` (GNOME), `Delete` (KDE), `Delete` (Emacs), `Delete` (Sublime Text), `⌦` (Sublime Text (macOS)), `Delete` (Visual Studio), `⌦` (Visual Studio (macOS)), `Delete` (NetBeans), `Delete` (Eclipse), `⌦` (Eclipse (macOS))。

* 或者，要移除外部服务器，请在项目视图 `Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Ctrl+1` (NetBeans), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS)) 中右键点击该服务器，并从上下文菜单中选择  `删除`  `Delete` (Windows), `⌦` (macOS), `⌦` (IntelliJ IDEA Classic (macOS)), `⌦` (macOS System Shortcuts), `Delete` (XWin), `Delete` (GNOME), `Delete` (KDE), `Delete` (Emacs), `Delete` (Sublime Text), `⌦` (Sublime Text (macOS)), `Delete` (Visual Studio), `⌦` (Visual Studio (macOS)), `Delete` (NetBeans), `Delete` (Eclipse), `⌦` (Eclipse (macOS))。

## 启动本地 Jupyter 服务器

Procedure:

1. 点击 Jupyter 笔记本工具栏上的服务器列表，并从上下文菜单中选择您要启动的服务器。

2. 要运行 Jupyter 服务器，请 [执行任何代码单元](running-jupyter-notebook-cells.html#execute-cell)。 当您启动单元执行时，IntelliJ IDEA 会在本地主机上使用任何可用端口（默认情况下为 8888 端口）启动 Jupyter 服务器。 您可以切换到   Jupyter 服务器   工具窗口以预览服务器的配置详情。

![Jupyter 服务器正在运行。 Jupyter 工具窗口](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_jupyter_tool_window.png)

## 停止 Jupyter 服务器

Procedure:

要停止任何正在运行的服务器，请切换到   Jupyter 服务器   工具窗口，然后点击 ![停止 Jupyter 服务器](https://resources.jetbrains.com.cn/help/img/idea/2026.3/app-client.expui.run.stop.svg)   停止 Jupyter 服务器  。 在   服务器日志  窗口中预览状态。

![停止服务器](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_jupyter_stop_server.png)

一旦关闭服务器，当前会话将被终止。 下次启动服务器时，所有先前会话和所有 notebook 的执行结果将丢失。

## 内核操作

### 重启 kernel

Procedure:

您可能想在不关闭整个服务器并不影响其他笔记本的情况下刷新您的计算。 要重新启动当前运行的 kernel，请点击 ![内核](https://resources.jetbrains.com.cn/help/img/idea/2026.3/python-jupyter.icons.com.jetbrains.python.jupyter.expui.restartKernel.svg) 在 [Jupyter notebook 工具栏](jupyter-notebook-support.html#toolbar) 上。 您可以在   服务器日志   窗口中查看内核状态：

![正在重启当前内核](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_jupyter_restart_kernel.png)

### 关闭内核

Procedure:

要完全停止正在运行的内核，请打开 Jupyter 笔记本工具栏上的服务器列表，并从上下文菜单中选择   关闭内核  。 此操作将终止当前的内核会话。

![关闭内核](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_shutdown_kernel.png)

### 切换内核

Procedure:

如果您至少有两个可用的内核，并且需要切换到其他内核，请打开 Jupyter 笔记本工具栏上的服务器列表。 从上下文菜单中选择   切换内核  ，然后从下拉列表中选择所需的内核。

![切换内核](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_switch_kernel.png)

### 将内核连接到服务器

Procedure:

在选择远程 Jupyter 服务器并打开笔记本后，运行第一个单元格后内核列表将自动可用。

不过，您也可以在运行任何单元格之前手动连接到服务器。 添加外部服务器后，点击 ![](https://resources.jetbrains.com.cn/help/img/idea/2026.3/app.expui.general.refresh.svg)   连接到服务器  按钮，位于 [Jupyter notebook 工具栏](jupyter-notebook-support.html#toolbar)上。 这将建立内核与 Jupyter 服务器之间的连接。

![将内核连接到服务器](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_connect_kernel.png)

