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

VS Code本地环境中Anaconda调用错误Python版本致Jupyter崩溃

解决VS Code中Jupyter扩展崩溃及Python解释器不匹配问题

核心问题定位

VS Code未正确关联Anaconda创建的Python3.11.5环境,强制使用了系统默认的Python2.7.16,而Jupyter扩展依赖Python3环境,这是导致扩展主机崩溃的直接原因。

解决步骤

1. 手动指定VS Code的Python解释器

  • 按下Cmd+Shift+P打开命令面板,输入Python: Select Interpreter
  • 在弹出的选项列表中,选择你的conda环境对应的Python路径:
    • Base环境:/Users/myname/anaconda3/bin/python
    • 项目专属环境:/Users/myname/Projects/myproject/.conda/bin/python
  • 如果列表中未显示目标路径,选择Enter interpreter path手动输入上述路径

2. 修复VS Code的终端环境继承

  • 打开VS Code设置(Cmd+,),搜索terminal.integrated.inheritEnv,确保该选项处于勾选状态
  • 若仍未生效,手动配置终端shell路径:
    1. 在设置中搜索terminal.integrated.shell.osx
    2. 将路径修改为你日常使用的终端shell(比如/bin/zsh或/bin/bash)
    3. 重启VS Code后再次尝试选择解释器

3. 强制项目使用指定Python环境

  • 在项目根目录下创建.vscode/settings.json文件(若已存在则直接编辑),添加以下配置:
{
  "python.pythonPath": "/Users/myname/Projects/myproject/.conda/bin/python",
  "jupyter.pythonCommand": "/Users/myname/Projects/myproject/.conda/bin/python"
}
  • 将上述路径替换为你实际使用的conda环境Python路径,确保Jupyter内核强制使用该解释器

4. 验证修复效果

  • 打开VS Code内置终端,执行python --version,确认输出为Python 3.11.5
  • 打开ipynb文件,选择指定的conda环境作为Jupyter内核,运行print("hello")测试

内容的提问来源于stack exchange,提问作者Typhaon

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 06:25:07