Skip to content

Using the Python Debugger

Matthew Beech edited this page Nov 18, 2024 · 2 revisions

Set up the Python debugger in VS Code.

  1. Select Run > Add Configuration from the VS Code menu bar.
  2. Select Python, and then Module, and enter the name of the module you want to debug, e.g. silnlp.nmt.translate.
  3. Edit configuration.
    • Add the option "console": "integratedTerminal"
    • Change "justMyCode" to "false"
    • Add "args": [] and fill the list with the arguments needed to run the module. See example below.
    • (Optional) To change or add environment variables for the duration of the debugger run, add "env": {} and put any variables you want in the dictionary. See example below.
    • (Optional) Change "name" to match the module
  4. To run, open the Run and Debug tab in VS Code (Ctrl+Shift+D), select a module at the top, and click the play button.

Example launch.json file

{
"version": "0.2.0",
"configurations": [
    {
        "name": "NMT Translate",
        "type": "python",
        "request": "launch",
        "console": "integratedTerminal",
        "justMyCode": false,
        "module": "silnlp.nmt.translate",
        "args": [
            "experiment_dir",
            "--clearml-queue",
            "jobs_backlog",
            "--src-project",
            "NIV11",
            "--books",
            "1JN"
        ],
        "env": {
            "SIL_NLP_DATA_PATH": "/home/user/alternate_data_path"
        }
    },
],
}