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 ?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

I was looking for this answer. Unfortunately it does not work. Nevertheless I have voted this up as it provides clarity.
I'm sorry I didn't help you. But can you tell me how it doesn't work?
Yes, the answer good and eliminated a potential issue, but was not working because of another (specific VScode) bug which is correctly resolved here: stackoverflow.com/questions/72914993/…. Hope that feedback is useful to everyone too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.