11

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.

9 Answers 9

20

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.

0
9

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.

1
  • 2
    It might be worth adding that this makes a change in .vscode/settings.json. Specifically, it adds a line like "python.pythonPath": "C:\\Users\\Username\\Anaconda3\\envs\\ProjectX\\python.exe"
    – craq
    Commented Jun 10, 2021 at 21:39
7

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
1
  • 2
    I had to first uninstall and reinstall the plugin to get the Reload required button. Commented Aug 6, 2021 at 18:16
5

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.

0

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"
}
4
0

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.).

0

add "cwd": "${fileDirname}"

like so

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

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

-1

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.