VS Code中运行Jupyter Notebook失败求助:jupyter-notebook命令未找到
解决VS Code中Jupyter Notebook找不到
jupyter-notebook命令的问题 问题场景
在VS Code中运行含print("hello world")的Jupyter Notebook时,报错:
启动Kernel失败,Jupyter服务器崩溃无法连接,Jupyter返回错误码1,提示“Jupyter command
jupyter-notebooknot found”
但在激活相同Python环境的终端中,直接运行jupyter-notebook能正常启动服务器。
核心原因
VS Code未正确识别当前激活Python环境中的Jupyter路径,或者其内部加载的环境变量与终端环境不一致。
解决方案
确认VS Code选中的解释器为目标环境
点击VS Code左下角状态栏的Python版本号,选择和终端激活的完全一致的环境(比如conda虚拟环境、venv虚拟环境);也可以通过快捷键Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(Mac)打开命令面板,输入Python: Select Interpreter选择对应环境。强制指定Jupyter服务器的解释器
打开命令面板,输入Jupyter: Select Interpreter to Start Jupyter Server,选择目标Python环境,让VS Code重新关联该环境下的Jupyter组件。手动配置Jupyter路径(兜底方案)
- 在激活目标环境的终端中,运行命令获取Jupyter的实际路径:
- Linux/Mac:
which jupyter-notebook - Windows:
where jupyter-notebook
- Linux/Mac:
- 打开VS Code设置(快捷键
Ctrl+,),搜索jupyter.jupyterPath,将上述路径粘贴进去(Windows路径需转义反斜杠,比如C:\\Users\\xxx\\env\\Scripts\\jupyter-notebook.exe)。
- 在激活目标环境的终端中,运行命令获取Jupyter的实际路径:
重启VS Code验证
完成上述设置后,关闭并重新打开VS Code,再尝试运行Notebook中的代码。
内容的提问来源于stack exchange,提问作者Josh Purtell
相关产品推荐
相关产品推荐

