Home >Backend Development >Python Tutorial >How to Set the Working Directory for Python Debugging in Visual Studio Code?
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:
<code class="json">"cwd": "${fileDirname}"</code>
Consider the "purpose" option (optional):
<code class="json">"purpose": ["debug-in-terminal"]</code>
Save your launch.json file:
Example launch.json configuration:
<code class="json">{ "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"] } ] }</code>
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.
The above is the detailed content of How to Set the Working Directory for Python Debugging in Visual Studio Code?. For more information, please follow other related articles on the PHP Chinese website!