VSCode更新后无法运行Jupyter Notebook求助(M1 Mac环境)
问题详情
更新VSCode至2023年1月的1.75版本后,Jupyter Notebook无法启动,核心报错为Jupyter command jupyter-notebook not found,完整错误日志如下:
Failed to start the Kernel. Jupyter server crashed. Unable to connect. Error code from Jupyter: 1 usage: jupyter.py [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir] [--paths] [--json] [--debug] [subcommand] Jupyter: Interactive Computing positional arguments: subcommand the subcommand to launch options: -h, --help show this help message and exit --version show the versions of core jupyter packages and exit --config-dir show Jupyter config dir --data-dir show Jupyter data dir --runtime-dir show Jupyter runtime dir --paths show all Jupyter paths. Add --json for machine-readable format. --json output paths as machine-readable json --debug output debug information about paths Available subcommands: kernel kernelspec migrate run troubleshoot Jupyter command jupyter-notebook not found. View Jupyter log for further details.
当前环境信息:
- 设备:MacBook Pro M1 Max
- VSCode版本:1.75(2023年1月发布)
- 扩展版本:Python v2023.2.0、Jupyter v2023.1.2010391206
已尝试但无效的操作:
- 终端中
jupyter-notebook可正常运行 - 新建conda/Python虚拟环境并安装Jupyter
- 完全卸载VSCode及相关目录后重装
- 切换Jupyter、Python扩展至预发布版本
- 更新jupyter、notebook库
- 使用
code --no-sandbox启动VSCode
可行解决方案尝试
指定Jupyter服务器路径
打开VSCode设置,搜索Jupyter: Server Path,将值设置为终端中which jupyter-notebook返回的完整路径(例如/opt/homebrew/bin/jupyter-notebook或虚拟环境内的路径),强制VSCode使用可正常运行的Jupyter实例。修复VSCode环境变量继承
M1设备默认终端为zsh,VSCode可能未正确继承系统PATH。在VSCode设置中搜索Terminal > Integrated > Env: Osx,添加配置:"terminal.integrated.env.osx": { "PATH": "/opt/homebrew/bin:/usr/local/bin:$PATH" }确保brew、conda等包管理工具的路径被包含,让VSCode能定位到Jupyter命令。
手动连接外部Jupyter服务器
在终端执行jupyter notebook --no-browser,复制输出中的服务器URL(格式为http://localhost:8888/?token=xxx);在VSCode的Jupyter面板选择「Connect to Existing Jupyter Server」,粘贴URL完成连接。禁用Jupyter扩展的服务器激活校验
搜索VSCode设置Jupyter: Server Requires Activation,取消勾选该选项,跳过扩展自动激活服务器的流程。临时降级VSCode版本
若以上方法均无效,可暂时降级至VSCode 1.74版本,等待官方修复M1平台的兼容性问题。从VSCode官方版本归档页面下载旧版本安装即可。
内容的提问来源于stack exchange,提问作者Mohammad Khalkhali

