I can see that this question has been asked multiple times already however, none of the solutions seems to be working anymore, forcing me to ask for the latest fix.
Problem
I have created a workspace in VS code with the following directory structure,
- work__assignments (this is my main workspace folder in vs code)
- assignment__1
- data
- modules
- tests
- assignment__2
- data
- modules
- tests
- assignment__1
"work__assignments" is my main workspace folder in the VS code. From this main workspace, I go to an assignment folder (e.g. work__assignments > assignment__2 > modules) and work on the respective code. However, when I try to debug the code in "work__assignments > assignment__2 > modules" the debugger loads from the main workspace folder (i.e. work__assignments), then it fails because it can't find other modules in the modules folder "work__assignments > assignment__2 > modules".
I have tried the following methods so far,
- Updating the launch.json file and adding the line
"cwd": "${fileDirname}",
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${fileDirname}"
}
- Updating the launch.json file and adding the line
"cwd": "",
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": ""
}
- Updating the launch.json file and adding the following lines,
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}",
"env": {
"PYTHONPATH": "${cwd}"
}
}
However, NONE OF THESE APPROACHES HAVE WORKED. Every time I debug the code, it launches into the workspace folder and not in the code folder. What am I doing wrong?
Note: I am running the debugger using the "Debug Python File" button at the top right corner as shown in the picture below,







cwdto"cwd": "./assignment__2".