@ SpeedCoder5 comment deserves to be the answer;
In particular, you can specify a dynamic working directory; (i.e., any directory that contains the currently open Python file) using "cwd": "${fileDirname}"
If you use the Python: Current File (Integrated Terminal) option when starting Python, your launch.json file might look like launch.json below.
{ "version": "0.2.0", "configurations": [ { "name": "Python: Current File (Integrated Terminal)", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "cwd": "${fileDirname}" }, //... other settings, but I modified the "Current File" setting above ... }
Remember that the launch.json file controls the startup / debugging settings of your Visual Studio Code project ; my launch.json file was automatically generated by VS Code in the directory of my current Open Project. I simply edited the file manually by adding "cwd": "${fileDirname}" as shown above.
If you do not have a launch.json file, try this :
To create a launch.json file, open your project’s folder in VS Code (File> Open Folder), and then select the Configure Engine icon in the top Debug panel.
source share