How to Set the Working Directory for Debugging a Python Program with VS Code's Debugger?
When debugging a Python program with Visual Studio Code (VS Code), specifying the working directory is crucial to ensure that your script runs correctly.
To set the working directory in your launch configuration file (launch.json), follow these steps:
Open your launch.json file:
Set the "cwd" variable:
"cwd": "${fileDirname}"
Consider the "purpose" option (optional):
"purpose": ["debug-in-terminal"]
Save your launch.json file:
Example launch.json configuration:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Current File (Integrated Terminal)",
"request": "launch",
"type": "python",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${fileDirname}",
"purpose": ["debug-in-terminal"]
}
]
}
Note: The launch.json file controls the debug settings for your project. If you do not have one, create it by clicking the Configure gear icon in the Debug view.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3