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

VS Code运行Python程序时反复打印“Unable to find python module.”求助

原因分析与修复方案

核心原因

你当前使用的是MSYS2 Mingw64 Python,VSCode Python扩展自带的debugpy调试工具和这个第三方编译的Python版本存在兼容性适配问题——调试启动时,debugpy无法正确加载依赖模块,虽然最终代码能正常执行,但会抛出重复的"Unable to find python module."错误。

可行修复步骤

1. 切换到官方Windows Python(最省心的方案)

放弃使用MSYS2的Python,换成Python官方发行的Windows版本,配置VSCode选中这个官方解释器后重新测试。官方版本和VSCode调试工具的适配性经过充分验证,大概率能直接解决问题。

2. 手动替换debugpy版本

如果不想更换Python环境,试试手动安装适配MSYS2 Python的debugpy:

  • 打开MSYS2终端,执行pip install --upgrade debugpy,确保安装的是最新兼容版本。
  • 打开VSCode的settings.json,添加以下配置,强制让调试器使用你本地安装的debugpy:
    "python.debuggerPath": "C:/msys64/mingw64/bin/python.exe -m debugpy.adapter"
    
    注意路径使用Windows格式的正斜杠,避免MSYS和Windows路径格式冲突。

3. 修正VSCode解释器配置

  • 按Ctrl+Shift+P打开命令面板,选择Python: Select Interpreter,确认选中的是C:\msys64\mingw64\bin\python.exe,不要选MSYS2终端里的类Unix路径。
  • 检查.vscode/settings.json,确保python.defaultInterpreterPath指向正确的Windows路径,没有拼写错误。

4. 限制调试器仅关注你的代码

在.vscode/launch.json中添加"justMyCode": true,让调试器跳过系统模块的检查,减少无意义的报错:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true
        }
    ]
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 16:50:27