VSCode — how to set working directory for debug

前端 未结 7 1395
耶瑟儿~
耶瑟儿~ 2020-11-27 03:10

I\'m starting to use vscode for Python. I have a simple test program. I want to run it under debug and I need to set the working directory for the run.

How/where d

相关标签:
7条回答
  • 2020-11-27 03:34

    In some cases, it might be also useful to set the PYTHONPATH along with the workspaceFolder:

    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal",
        "cwd": "${workspaceFolder}",
        "env": {
            "PYTHONPATH": "${cwd}"
        }
    }
    
    
    0 讨论(0)
  • 2020-11-27 03:36

    To set current working directory to whatever file you are executing at the time:

    File > Preferences > Settings > Python > Data Science > Execute in File Dir

    Thanks brch: Python in VSCode: Set working directory to python file's path everytime

    0 讨论(0)
  • 2020-11-27 03:41

    I am posting this sample configuration for people who use TypeScript on Node.js

    in my project my Node.js server TypeScript files are located in folder Application_ts and the compiled js files are generated in the folder named Application

    because when we run our application in debug mode or start it normally we should start from Application folder which contains the js files so bellow configuration run debug from root folder where my application_ts also exists and works perfect

    {
      "version": "0.2.0",
      "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Debug TypeScript in Node.js",
            "program": "${workspaceRoot}\\Application\\app.js",
            "cwd": "${workspaceRoot}\\Application",
            "protocol": "inspector",
            "outFiles": [],
            "sourceMaps": true
        },        
        {
            "type": "node",
            "request": "attach",
            "name": "Attach to Process",
            "port": 5858,
            "outFiles": [],
            "sourceMaps": true
        }
     ]
    }
    
    0 讨论(0)
  • 2020-11-27 03:42

    This setting 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
    }
    
    0 讨论(0)
  • 2020-11-27 03:42

    You can set up current working directory for debugged program using cwd argument in launch.json

    0 讨论(0)
  • 2020-11-27 03:46

    All you need to do is configure the cwd setting in 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 docs website.

    0 讨论(0)
提交回复
热议问题