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

VSCode调试Streamlit报错,如何修改launch.json解决?

解决VSCode中Streamlit调试的文件扩展名错误问题

问题原因

你在Streamlit调试配置里使用了错误的VSCode变量格式$(file),这个写法无法被正确解析为当前打开的Python文件路径,导致Streamlit收到未解析的$(file)字符串,被识别为无扩展名的文件,进而触发报错。

修改方案

将args中的$(file)替换为VSCode标准变量格式${file},修改后的完整launch.json配置如下:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: Current File",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "debug streamlit",
            "type": "debugpy",
            "request": "launch",
            "module": "streamlit",
            "args": [
                "run",
                "${file}"
            ]
        }
    ]
}

验证效果

修改后重新启动调试,VSCode会将${file}正确替换为当前打开的Python文件完整路径,Streamlit就能识别到合法的.py文件,正常启动调试流程。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 12:42:03