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
相关产品推荐
相关产品推荐

