0

In VS Code on Ubuntu 20.04, when I press F5 to run a python script, I get:

"The Python path in your debug configuration is invalid."

Here is the relevant part of my launch.json:

   "configurations": [
        {
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "python": "/home/ian/anaconda3/bin/python3",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },

I have the correct Debug configutation set:

enter image description here

When I run /home/ian/anaconda3/bin/python3 it works fine.

For what it's worth, in the integrated terminal both

which python

and

which python3

Return /home/ian/anaconda3/bin/python (3)

How can I get VS Code to run python?

4
  • Since python is in path just defining "python": "python3" should work Commented Sep 28, 2022 at 12:59
  • When I do that VS Code does run the script, but it uses the wrong python: it uses /usr/bin/env /usr/bin/python3 Commented Sep 28, 2022 at 13:01
  • Oh, I've found the issue, it's in my .bashrc file Commented Sep 28, 2022 at 13:02
  • No I haven't - removed an alias in .bashrc and it still hasn't fixed it Commented Sep 28, 2022 at 13:04

1 Answer 1

1

You could try this configuration, it works for me:

    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true
        }
    ]

PS: As Omroth said, I have selected an interpreter before, so I don't need to specify python command in launch.json.

If you need to choose Python interpreter, use shortcuts "Ctrl+Shift+P" and type "Python: Select interpreter".

enter image description here

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

3 Comments

That leads to this error: "You need to select a Python interpreter before you start debugging. Tip: click on "Select Interpreter" in the status bar"
@Omroth Try "Ctrl+Shift+P" and type "Python: Select interpreter" to choose the interpreter.
This in combination with MingJieMSFT's comment is the correct answer, thank you

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.