How to correctly set specific module to debug in VS code?

You are using module instead of program in launch.json. When using module you must pass only the module\sub-module name, not the entire path. Visual Studio will then load the specified module and execute it's __main__.py file.

This would be the correct input, assuming automl is a module and experiments is a submodule:

"module": "automl.experiments"

If you want to point to your script directly you can use the path you were using previously, just changing module to program:

"program": "${workspaceFolder}/automl/experiments/experiments_model_optimization.py"


So this is what I did. Once I opened the launch.json file by going to the debugger tab on the left:

enter image description here

then I clicked on Add configuration and then the launch.json file opened. Then at the bottom right there is a blue botton with Add Configuration:

enter image description here

then I filled in the stex that appeared after selecting Python file. The text that appeared was:

        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }

and I changed it to:

        {
            "name": "Python: My Trainable",
            "type": "python",
            "request": "launch",
            "program": "/Users/brandomiranda/automl-meta-learning/prototyping_tests_playground/trainable_optimizers/my_trainable.py",
            "console": "integratedTerminal"
        },

then I made sure I selected it on the left debug menu so that each time I ran it with the F5 short cut it ran the right file no matter where I was in VS code.


Current file:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Python: My Trainable Step Size Higher",
            "type": "python",
            "request": "launch",
            "program": "/Users/brandomiranda/automl-meta-learning/prototyping_tests_playground/trainable_optimizers/trainable_step_size.py",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Experiments Protype1",
            "type": "python",
            "request": "launch",
            "program": "${env:HOME}/automl-meta-learning/automl/experiments/experiments_model_optimization.py",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "localhost",
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ]
        },
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "module": "enter-your-module-name-here",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "console": "integratedTerminal",
            "args": [
                "runserver",
                "--noreload",
                "--nothreading"
            ],
            "django": true
        },
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app.py"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true
        },
        {
            "name": "Python: Current File (External Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "externalTerminal"
        }
    ]
}

seems ${end:HOME} is important for getting home path.