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

VSCode调试Python文件无结果问题(Python 3.7.0环境)

VSCode调试Python 3.7.0项目无输出,Python 3.12.6正常的问题排查与解决

问题概述

在Windows系统的VSCode中调试Python项目时遇到以下情况:

  • 右键文件选择「run file in terminal」可正常运行,执行命令:
    C:/Users/rmarr/Documents/python-envs/.mlagents/Scripts/python.exe c:/Users/rmarr/Documents/python-envs/.mlagents/Lib/site-packages/mlagents/learn-copy.py
    
  • 使用Python调试器运行无任何结果,当前launch.json配置:
    {
        "version": "0.2.0",
        "configurations": [
          {
            "name": "Python: Current File",
            "type": "debugpy",
            "request": "launch",
            "program": "${workspaceFolder}/learn-copy.py",
            "console": "integratedTerminal",
            "justMyCode": false
          }
        ]
    }
    
  • 调试启动时CLI显示命令:
    cmd /C "c:\Users\rmarr\Documents\python-envs\.mlagents\Scripts\python.exe c:\Users\rmarr\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher 57348 -- C:\Users\rmarr\Documents\python-envs\.mlagents\Lib\site-packages\mlagents/learn-copy.py 
    
  • 已确认:常规终端和调试终端均激活虚拟环境、设置"justMyCode": false、添加断点;Python 3.12.6环境下调试正常,但必须使用Python 3.7.0环境。

核心原因:debugpy版本兼容性问题

最新版VSCode Python插件(ms-python.debugpy-2024.10.0)捆绑的debugpy版本较高,而Python 3.7已进入维护阶段,debugpy后续版本不再对其提供完善支持,导致调试过程无输出、断点不触发。Python 3.12作为较新版本,与当前debugpy兼容性良好,因此调试正常。

解决办法

方法1:降级虚拟环境中的debugpy到兼容版本

在激活的Python 3.7虚拟环境中执行以下命令,安装最后一个支持Python 3.7的debugpy版本:

pip install debugpy==1.6.7

然后修改launch.json,指定使用虚拟环境中的debugpy路径,避免使用插件捆绑的版本:

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Python: Current File",
        "type": "debugpy",
        "request": "launch",
        "program": "${workspaceFolder}/learn-copy.py",
        "console": "integratedTerminal",
        "justMyCode": false,
        "debugPath": "C:/Users/rmarr/Documents/python-envs/.mlagents/Scripts/debugpy.exe"
      }
    ]
}

方法2:降级VSCode Python插件

如果方法1无效,可以降级VSCode的Python插件到兼容Python 3.7的旧版本:

  • 打开VSCode扩展市场,找到「Python」插件(ms-python.python)
  • 点击插件详情页的「管理」按钮(三个点图标),选择「安装另一个版本」
  • 选择2023.x系列版本(该版本捆绑的debugpy仍支持Python 3.7)

验证

修改完成后重启VSCode,启动调试器,检查终端是否有输出、断点是否正常触发。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 02:25:54