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

VS Code中Kivy应用调试模式无法启动,调试后需重启编辑器才能正常运行的问题求助

VS Code中Kivy应用调试模式无法启动,调试后需重启编辑器才能正常运行的问题求助

我平时一直用VS Code写Python代码,之前都没出过问题,但现在遇到个棘手的情况:Kivy应用可以在VS Code中正常运行(不调试),但一尝试启动调试模式,应用就完全没反应。不管是用菜单里的“Debug Python File”选项,还是用下面这个launch.json配置,结果都一样:

{
            "name": "Debug Kivy App",

            "type": "debugpy",

            "request": "launch",

            "program": "${workspaceFolder}/main.py",

            "args": ["--debug"]
            // Note: I've tried it with and without "args" : ["--debug"]
}

更麻烦的是,一旦尝试过调试模式,我必须关闭并重启VS Code,才能再次正常运行这个应用(不调试)。

我写了一个极简的测试应用来复现问题,它能正常运行,但调试模式下就是启动不了:

from typing import Self

from kivy.app import App
from kivy.uix.button import Button

class DebugTest(App):
    def build(self : Self) -> Button:
        return Button(text="blah", on_release = self.button_press)
    
    def button_press(self : Self, instance : Button) -> None:
        print("Button pressed")

if __name__ == '__main__':
    DebugTest().run()

我的环境信息:

  • 操作系统:Ubuntu 24.10
  • VS Code版本:1.96.4(当前最新版)
  • Python版本:3.13.0(Kivy官网确认该版本兼容)

调试模式下完全没有输出,但正常运行时的输出是这样的:

kivytestrobert@rubunnytu:~/python/3.13.0/db_test$ /home/robert/.pyenv/versions/3.13.0/envs/kivytest/bin/python /home/robert/python/3.13.0/db_test/main.py
[INFO   ] [Logger      ] Record log in /home/robert/.kivy/logs/kivy_25-01-29_8.txt
[INFO   ] [Kivy        ] v2.3.1
[INFO   ] [Kivy        ] Installed at "/home/robert/.pyenv/versions/3.13.0/envs/kivytest/lib/python3.13/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.13.0 (main, Oct 14 2024, 11:37:50) [GCC 13.2.0]
[INFO   ] [Python      ] Interpreter at "/home/robert/.pyenv/versions/3.13.0/envs/kivytest/bin/python"
[INFO   ] [Logger      ] Purge log fired. Processing...
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [Factory     ] 195 symbols loaded
[INFO   ] [ImageLoaderFFPy] Using ffpyplayer 4.5.2
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_ffpyplayer 
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'4.6 (Compatibility Profile) Mesa 24.2.3-1ubuntu1'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel'>
[INFO   ] [GL          ] OpenGL renderer <b'Mesa Intel(R) HD Graphics 530 (SKL GT2)'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 6
[INFO   ] [GL          ] Shading version <b'4.60'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [Base        ] Leaving application in progress...
kivytestrobert@rubunnytu:~/python/3.13.0/db_test$

尝试调试后,我运行ps -aux | grep -i python得到的结果如下,不确定有没有关联,但还是贴出来:

robert    152988  0.4  0.0   6164  4848 ?        S    15:39   0:01 /home/robert/.vscode/extensions/ms-python.python-2024.22.2-linux-x64/python-env-tools/bin/pet server
robert    153853  4.3  1.4 1214080120 234556 ?   Sl   15:39   0:08 /usr/share/code/code /home/robert/.vscode/extensions/ms-python.vscode-pylance-2024.12.1/dist/server.bundle.js --cancellationReceive=file:27507b40408191bdb10300c13fc80a5472ab60567d --node-ipc --clientProcessId=152901

我已经在网上搜了各种解决方案,但都没解决问题。真心希望有人能帮我一把,我习惯用VS Code写Python,不想为了Kivy切换到其他IDE。


编辑:问题解决了!
原因似乎和插件有关。我删除了.vscode目录,重新启动VS Code后只安装了最必需的插件,现在调试模式可以正常工作了。等这个项目做完,我会逐个加回其他插件,找出到底是哪个插件导致的冲突。

备注:内容来源于stack exchange,提问作者R. Riggs

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 15:28:05