參考:https://blog.csdn.net/yscoder/article/details/102556006
在vscode中如果使用相對路徑打開文件時,直接在當前目錄運行是沒有問題的,但是使用調試模式時會提示找不到文件,是因為調試模式會自動進入調試模式配置文件的文件夾
在vscode中, 點擊 調試->打開配置 ,在打開的launch.json文件增加 "cwd":"" ,
修改步驟如下
修改完的配置如下
{ // 使用 IntelliSense 了解相關屬性。 // 懸停以查看現有屬性的描述。 // 欲了解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: 當前文件", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "stopOnEntry": true, "cwd": "" } ] }