0

I try to get VS code debug (F5 key) to run from the same place as the Run Python File.

The run code path is here:

c:/Users/Username/.Tactical/Local/envs/lon/python.exe

What i have tired so far (quite a bit from a previous question): run python script in VS code works with run python file button, but not F5 key

I now wish to make the launch.json point explicitly to the same path.

The launch.json configuration looks like this:

{
"name": "Python: Base Console", // i am tesing this.
"type": "python",
"request": "launch",
"program": "${file}",  // can the user change this line to the correct python.exe ?
"console": "integratedTerminal"
}

I tried to change the ${file} to the path, but this failed. Have I understood this correctly or what should I do to point to the correct python.exe ?

D.L
  • 4,339
  • 5
  • 22
  • 45

1 Answers1

1

The "program" configuration in launch.json is the entry module of the program.

If you want to specify the python interpreter for debugging, use the "python" configuration.

A simple example:

{
    // 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": ".venv",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "python": "C:\\WorkSpace\\PyTest0628\\.venv\\Scripts\\python.exe"
        },
        {
            "name": "anaconda",
            "type": "python",
            "request": "launch",
            "program": "C:\\WorkSpace\\PyTest0628\\Test6.py",
            "console": "integratedTerminal",
            "justMyCode": true,
            "python": "C:\\Users\\Admin\\anaconda3\\python.exe"
        }
    ]
}

You can choose which configuration to use in the debug window:

enter image description here

More configuration information about launch.json: https://code.visualstudio.com/docs/python/debugging#_set-configuration-options

JialeDu
  • 6,021
  • 2
  • 5
  • 24
  • I was looking for this answer. Unfortunately it does not work. Nevertheless I have voted this up as it provides clarity. – D.L Jul 12 '22 at 08:03
  • I'm sorry I didn't help you. But can you tell me how it doesn't work? – JialeDu Jul 15 '22 at 02:43
  • Yes, the answer good and eliminated a potential issue, but was not working because of another (specific VScode) bug which is correctly resolved here: https://stackoverflow.com/questions/72914993/run-python-script-in-vs-code-works-with-run-python-file-button-but-not-f5-key. Hope that feedback is useful to everyone too. – D.L Jul 15 '22 at 09:42