VSCode - how to set working directory for debugging

I am starting to use vscode for Python. I have a simple test program. I want to run it under debugging, and I need to set the working directory to run.

How / where am I doing this?

+28
source share
4 answers

@ 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.

+23
source

All you have to do is configure the cwd parameter in the launch.json file as follows: { "name": "Python", "type": "python", "pythonPath":"python",.... "cwd": "<Path to the directory>".... }

More information about this can be found on the official VS Code documentation website .

+35
source

This option helps me:

 { "type": "node", "request": "launch", "name": "Launch Program", "cwd": "${workspaceFolder}\\app\\js", // set directory here "program": "${workspaceFolder}\\app\\js\\server.js", // set start js here } 
+7
source

You can configure the current working directory for a debugged program using the cwd argument in launch.json

+1
source

All Articles