PythonNoob-exe
PythonNoob-exe

Reputation: 161

VSCode: The Python path in your debug configuration is invalid

Very new to Python and VSCode (and stackoverflow). I've been using both for about 3 months now just fine, up until recently that is.

When trying to run any basic Python program in the debugger, the popup The Python path in your debug configuration is invalid. Source: Python(Extension) appears and the debugger won't run. I go to my launch.json file and sure enough, I have the path to where Python is set up.

{

"version": "0.2.0",
"configurations": [
    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal",
        "python": "${command:python.interpreterPath}"
    }
]

}

Messing with settings.json doesn't help anything either because I do have the path to Python set up, but the debugger still won't run. I am at a loss what to do here. I have never gone into my .json files in the past before, nor have I ever had to configure my Python path after installing VSCode for the first time.

Upvotes: 11

Views: 28300

Answers (9)

Piotr
Piotr

Reputation: 1937

Try to remove line from launch.json

"console": "integratedTerminal",

In my case i removed:

"console": "internalConsole",

Changed from

{
    "name": "Python: File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "internalConsole",
    "justMyCode": true,
}

to

{
    "name": "Python: File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "justMyCode": true,
}

and it worked

Upvotes: 0

Yu Da Chi
Yu Da Chi

Reputation: 109

add "cwd": "${fileDirname}"

like so

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

Upvotes: 0

Toru Kikuchi
Toru Kikuchi

Reputation: 382

My Case: I couldn't find the underlying reason, but could find a workaround as follows.

  • Do not use Run -> Start Debugging (or Run -> Run without Debugging). This raises the problem.
  • Instead, open the terminal. Change directory to where your python file is. Then, do command such as "python test.py".

This solves the problem and the code runs normally.

In short, my workaround is to use VSCode as only an editor, and run codes via terminals (command prompt, power shell etc.).

Upvotes: 0

Timo
Timo

Reputation: 3227

Tl;Dr

Restart Vscode

Findings to get there

  • Go to extensions view with ctrl+shift+x in Linux version or Menu -> View -> Extensions
  • Find blue Button Reload required for the Python Extension
  • Restart Vscode
  • It should work

Upvotes: 7

alvdky
alvdky

Reputation: 7

I had a similar problem in VScode today. I was getting the following error message every time I tried to run a script.

The Python path in your debug configuration is invalid.

The problem resolved itself when I opened a folder in the 'Explorer' tab on the left hand side of the screen. Not sure why this worked or if it was actually the problem ... maybe it will help someone.

Upvotes: -1

Bharath Gowda
Bharath Gowda

Reputation: 101

Vscode is not able to find the python path or its not yet set.

Open command palette(ctrl+shift+P) and type python and look for "Python:Select Interpreter". You will be asked to enter the path of python where it is installed.

Incase you are using virtual environment and in most of the case its true. Look for the path .venv/Script/python else select the python path where you have installed in your local machine.

Upvotes: 10

Kanishk Mewal
Kanishk Mewal

Reputation: 419

I was facing the same problem. Here's how I fixed it without having to uninstall:

Look at this image for reference:

Screenshot of VS Code

Click on the "Python 3.8.3 32-bit" down there in the corner (the version maybe different for you) and select your debugger or specify the location if it's not already there.

Upvotes: 20

PythonNoob-exe
PythonNoob-exe

Reputation: 161

Turns out I had to downgrade the version of my Python extension from Version 2021.3 to 2021.2, now VSCode can finally find the Python path.

Upvotes: 5

idy-3
idy-3

Reputation: 1

You could try something like this but directing it to wherever your python program is install on your system

{
    "python.pythonPath": "C:\\Python36\\python.exe"
}

Upvotes: 0

Related Questions