You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Windows VS Code/Jupyter中简化xeus-cling内核访问,无需手动处理WSL URL?

简化Windows 11下VS Code Jupyter Notebook使用C++的工作流程

环境配置

  • Windows 11 Pro Workstation(版本24H2,内部版本26100.2894)
  • WSL 2(Ubuntu 22.04.5 LTS)
  • VS Code 1.97.0(已安装Jupyter/Jupyter Notebook及C/C++扩展)
  • Conda 25.1.1(虚拟环境中安装xeus-cling 0.15.0)

当前工作流程

  1. 启动WSL实例
  2. 在WSL的Conda环境中执行jupyter notebook --no-browser启动Jupyter服务器
  3. 手动复制WSL生成的URL(例如:http://localhost:8888/?token=...)
  4. 将URL粘贴到VS Code的“输入运行中的Jupyter服务器URL”提示框中

该流程可行,但相比Windows原生Python/R内核的使用步骤过于繁琐。

已尝试方案

  • VS Code的“Remote - WSL”扩展:内核连接不稳定

需求目标

希望实现以下任一效果:

  • 与WSL中的Jupyter服务器建立持久/自动化连接
  • 在Windows上原生运行xeus-cling内核

具体要求:

  • VS Code启动时自动启动WSL的Jupyter服务
  • 自动完成URL/令牌认证
  • 维持内核连接稳定性(避免频繁更改端口)

解决方案

一、自动化连接WSL的Jupyter服务器

通过脚本和VS Code配置实现全自动化流程:

  1. 编写WSL端启动脚本
    在WSL中创建~/scripts/start_jupyter.sh文件,内容如下(替换your-env-name为你的Conda虚拟环境名,your-fixed-token为自定义的固定令牌):
#!/bin/bash
conda activate your-env-name
# 指定固定端口和令牌启动Jupyter,避免端口随机变化和手动复制令牌
jupyter notebook --no-browser --port=8888 --NotebookApp.token='your-fixed-token'

赋予脚本执行权限:

chmod +x ~/scripts/start_jupyter.sh
  1. 编写Windows端启动批处理
    在Windows本地创建start_wsl_jupyter.bat文件,内容如下(替换Ubuntu-22.04为你的WSL发行版名称):
wsl.exe -d Ubuntu-22.04 ~/scripts/start_jupyter.sh
  1. 配置VS Code自动连接固定服务器
    打开VS Code设置(快捷键Ctrl+,),搜索Jupyter: Server URI,设置值为:
http://localhost:8888/?token=your-fixed-token

保存后,VS Code会自动连接该固定服务器,无需手动输入URL。

  1. 设置VS Code启动时自动启动Jupyter服务
    按Ctrl+Shift+P打开命令面板,输入Tasks: Open User Tasks,选择创建tasks.json文件,替换内容为(替换C:\\path\\to\\your\\start_wsl_jupyter.bat为批处理文件的实际路径):
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Start WSL Jupyter",
            "type": "shell",
            "command": "C:\\path\\to\\your\\start_wsl_jupyter.bat",
            "runOptions": {
                "runOn": "folderOpen"
            },
            "problemMatcher": []
        }
    ]
}

此后打开VS Code时,会自动启动WSL中的Jupyter服务,并完成自动连接。

二、尝试Windows原生运行xeus-cling内核

xeus-cling对Windows的官方支持有限,但可尝试以下步骤:

  1. 安装Windows版Miniconda/Anaconda
  2. 创建并激活虚拟环境:
    conda create -n xeus-cling-env
    conda activate xeus-cling-env
    
  3. 安装xeus-cling:
    conda install -c conda-forge xeus-cling
    

注意:若安装失败,需先安装Visual Studio Build Tools并勾选C++开发组件;若仍无法解决,建议优先使用WSL方案,因为xeus-cling在Linux环境下的兼容性和稳定性更优。


内容的提问来源于stack exchange,提问作者wudl-21

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 10:48:16