Python VSCode调试的时候,代码中无法试用相对路径
使用VSCode调试Python程序
如果 有用到相对路径文件操作,则会报错
VSCode调试Python相对路径错误描述
发生异常: FileNotFoundError (note: full exception trace is shown but execution is paused at: <module>)
[Errno 2] No such file or directory: 'setting.cfg'
File "C:\Users\XQ-Garson\Desktop\Python\gz\runHttp.py", line 27, in <module> (Current frame) f = open('setting.cfg', 'r')
如图:
确认文件是存在的
解决办法
更改 launch.json 设置
选择 python 环境
调试模式,选择python文件
然后得到一个 launch.json 文件
configurations 中 添加
"cwd": "${fileDirname}",
保存后,就可以了
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
post 管理员