Меню

The python path in your debug configuration is invalid visual studio code ошибка

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.

Running with the isolated script seems to cause the interpreterInfo script to fail in this scenario:

C:UserskarthDownloadspython-3.8.3>python.exe "c:\GIT\issues\s p\vscode-python\pythonFiles\pyvsc-run-isolated.py" "c:\GIT\issues\s p\vscode-python\pythonFiles\interpreterInfo.py"
Traceback (most recent call last):
  File "c:\GIT\issues\s p\vscode-python\pythonFiles\pyvsc-run-isolated.py", line 23, in <module>
    runpy.run_path(module, run_name="__main__")
  File "runpy.py", line 265, in run_path
  File "runpy.py", line 97, in _run_module_code
  File "runpy.py", line 87, in _run_code
  File "c:\GIT\issues\s p\vscode-python\pythonFiles\interpreterInfo.py", line 4, in <module>
    import json
ModuleNotFoundError: No module named 'json'

C:UserskarthDownloadspython-3.8.3>python.exe "c:\GIT\issues\s p\vscode-python\pythonFiles\interpreterInfo.py"
{"versionInfo": [3, 8, 3, "final"], "sysPrefix": "C:\Users\karth\Downloads\python-3.8.3", "version": "3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]", "is64Bit": true}

This Visual Studio Code Python error happens when you have specified an invalid path to a Python interpreter in your .vscode/launch.json file in your project directory. You can fix it by either specifying the correct path, or removing the pythonPath attribute altogether. Also check that you have the correct environment selected in the command palette (Ctrl+Shift+P).

So I happened to inherit someone else’s code on a project. And that project used Visual Studio Code, pretty extensively. Not being familiar at all with VS Code (and also never wanting to get familiar with it), I went into the project a little naively. Assuming it was like a normal, modern, well-behaved IDE that didn’t have magical hidden files associated with it that drastically affected its behavior, I didn’t bother looking for any. Boy, was I wrong.

I happily worked on the Python code that fell into my lap for a while, then ran into a situation where I needed to debug it. “Easy” I thought. “I’ll just hit F5 like I always used to in Visual Studio and it’ll launch the debugger”. Well, I was right about that part. It will launch the debugger. Or, at least in my case, it’ll try to launch the debugger.

Here’s what I got instead:

Oh great, here we go! Don’t worry, I figured out what the problem was, so we’ll get into what we can do about this. Let’s start with the one that fixed it for me.

❌ Problem: pythonPath in your launch.json really is invalid

So, as it turns out, my assumption that VS Code doesn’t have magical hidden files that affect the behavior of your project was false. Who woulda thought? I mean, it is promoted as a hip, agile, slimmed down IDE for the cool kids. But, then again, it is also Microsoft Visual Studio. And they love their opaque and fragile project settings files.

So, I did a quick look around the project directory (including hidden files), and I found this:

$ tree -a
.
├── main.py
└── .vscode
    └── launch.json

1 directory, 2 files

What the heck is launch.json? Well, after a lot of searching around the web, I found on Microsoft’s help pages that it’s the project settings. Inside a hidden folder, of course. Because why wouldn’t it be?

Anyway, I looked inside and found this as the contents:

{
    // 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": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "pythonPath": "C:\Python3.8\bin\python.exe"
        }
    ]
}

Hmm… I think I know the problem. Can you guess?

That’s right, the pythonPath isn’t right. I’m on Ubuntu 20.04 as my usual development machine, and that, my friends, is a Windows path. Of course. The guy I took over for was using Windows to work on this, so he committed everything, including his Windows-specific VS Code settings with it. I mean, that’s not even the default install path for Python on Windows, that’s some package he probably downloaded and unzipped to the root of the C: drive.

Anyway, enough complaining, let’s fix it.

✅ Fix 1: put the correct path in launch.json

So, as you might have already guessed, we need to put the correct path to Python in here in order for this to work. In order to do that, we need to first figure out where our Python is installed. This will differ depending on your OS (Windows vs Mac vs Linux), so pick whichever you are on below and try it.

Find python binary on Mac, Linux, or WSL

Fire up a terminal and type in the following command:

This should result in the correct path to where your python command points to. If you don’t get any result, your Python interpreter is probably called python3 (or python2 if you’re still using Python 2) so try searching for that instead. Here’s mine:

$ which python3
/usr/bin/python3

Find python binary on Windows

This is a bit trickier, but not that bad. You could open up “My Computer” and aimlessly click around Program Files until you find it, but there’s a better way. Ok, maybe not better, but it’s guaranteed to work.

Open up a Python interpreter and try the following:

>>> import sys
>>> sys.executable
'C:\Program Files\Python\bin\python.exe'

Oh, look, there it is! What we did here was we used Python’s os package to get the path to the executable. Pretty neat.

Update your launch.json

Ok, now that we have our correct Python path (you did copy it, right?) we need to put that in our launch.json file for the property pythonPath. So open it up in VS Code and scroll down to the pythonPath property.

Here’s mine after fixing it:

{
    // 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": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "pythonPath": "/usr/bin/python3"
        }
    ]
}

And that’s what fixed it for me. However, I later learned that it’s not even necessary to specify it in there. What’s in the pythonPath in launch.json is more of an override, not a necessary setting that has to be there.

✅ Fix 2 (recommended): remove the pythonPath attribute from launch.json entirely

Another fix, like I said previously, is to just remove that property altogether. It’s not necessary, and it’s just an override for whichever Python interpreter path VS Code thinks it should use in the first place.

Here’s what it could look like if you just remove it:

{
    // 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": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true            
        }
    ]
}

I tried just removing it myself and it still worked. So, this would be my recommended solution.

❌ Problem: you selected an invalid Python environment

So if you’re not in my exact situation and you didn’t inherit someone else’s code that happened to be working on a different platform, good for you. That’s a great place to be. But, it also means you screwed something up in your own project. I know, I know. That’s impossible. But… hear me out. You did.

What you might have done is accidentally picked the wrong Python environment from the command palette. What is a “command palette” you ask? Well, fear not, I’ll tell you. I just learned about it 3 hours ago myself, so I’m kind of an expert.

In VS Code, the “command palette” is the thing that is brought up when you type Ctrl+Shift+P:

As you can see, in my recently used commands, I have Python: Select Interpreter. That’s because I was screwing around with this for way too long earlier trying to fix the problem. You probably won’t have anything under recently used, unless it’s how you messed things up in the first place. Don’t worry, I won’t tell anyone 😉

✅ Fix 1: open the command palette and select the correct environment

To fix this, we have to open up the command palette (see screenshot above) and type in “python select interpreter” like this:

Then, click on the “Python: Select Interpreter” option. You’ll see something like this:

Go ahead and choose the starred one that is “recommended”. If that doesn’t work, pick the next one down. And if that doesn’t work… well, you get the picture.

What if none of them work? Well…

❌ Problem: your VS Code install is corrupted

Sometimes, VS Code is just broken. Like any other fancy schmancy IDE, it has a lot of moving parts, lots of config files, and no-doubt some of those config files are in some obscure, proprietary, binary format that you’ll never be able to decipher or figure out why they’re not pointing to the right interpreter.

If trying to figure that out is your cup of tea, go for it. There’s probably a future in computer forensics for you. For the rest of us…

✅ Fix: reinstall VS Code

Time for the nuclear option! This is not usually my go-to solution (okay, maybe it kind of is), but it works 9 times out of 10 when some IDE is behaving badly and nothing seems to fix it. I could sit here and try to tell you that I know why VS Code in particular needs re-installing sometimes, but I’d be lying. It’s also not really something I particularly care about, especially when I have deadlines to meet and the thing just isn’t working.

So, go ahead. Uninstall it and re-install it. It’s what the IT guy will do anyway.

Conclusion

In this article we discussed the various causes of “The Python path in your debug configuration is invalid” and what to do about it. Well, there’s only one real cause: your launch.json is pointing to the wrong pythonPath. But it could also be some internal setting for VS Code. In which case, your best bet is to just reinstall it. If the problem is in your launch.json, you can either remove the pythonPath property altogether (recommended) or put the correct path in there. After you figure out what the correct path is, of course.

That’s all for now, happy coding!

Hello Guys, How are you all? Hope You all Are Fine. Today When I run my python code Suddenly I got VSCode: The Python path in your debug configuration is invalid in Python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

Contents

  1. How VSCode: The Python path in your debug configuration is invalid Error Occurs ?
  2. How To Solve VSCode: The Python path in your debug configuration is invalid Error ?
  3. Solution 1: add Python:Select Interpreter
  4. Solution 2: add python path in vscode
  5. Solution 3: add pythonPath
  6. Summery

I am trying to debug a simple python program via “F5” or “Run with debugger”. Whenever I press F5 using the python extension, a pop-up appears at the bottom right “The Python path in your debug configuration is invalid.”

How To Solve VSCode: The Python path in your debug configuration is invalid Error ?

  1. How To Solve VSCode: The Python path in your debug configuration is invalid Error ?

    To Solve VSCode: The Python path in your debug configuration is invalid just Open Command Palette (Ctrl + Shift + P). Type Python: Select Interpreter, open it Select the python interpreter or enter the full path to the python interpreter. 

Solution 1: add Python:Select Interpreter

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.

Solution 2: add python path in vscode

  1. See File - Preferences - Settings.
  2. Click the “Open Settings (JSON)” button. Make sure that this entry has python.exe at the end. "python.pythonPath": "C:\Users\<your_user_name>\AppData\Local\Programs\Python\Python38\python.exe

Solution 3: add pythonPath

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

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also Read

  • SyntaxError: invalid syntax to repo init in the AOSP code.

Today We are Going To Solve VSCode: The Python path in your debug configuration is invalid in Python. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.

Contents

  • 1 How to Fix VSCode: The Python path in your debug configuration is invalid Error?
    • 1.1 Solution 1 : Reload required for the Python Extension
    • 1.2 Solution 2 : Specify the location
    • 1.3 Solution 3 : Run this command
  • 2 Conclusion
    • 2.1 Also Read This Solutions
  1. How to Fix VSCode: The Python path in your debug configuration is invalid Error?

    To Fix VSCode: The Python path in your debug configuration is invalid Error just Reload required for the Python Extension. First of all, restart your Vscode and then just go to extensions view with ctrl+shift+x in Linux version. And there is a blue button. There just Reload required for the Python Extension and then restart the vscode. It will help you!

  2. VSCode: The Python path in your debug configuration is invalid

    To Fix VSCode: The Python path in your debug configuration is invalid Error just Specify the location. You can solve this error very easily. Just follow this steps. First of all Click on the Your python version which is at in the corner and select your debugger or specify the location if it’s not already there. By soing this you can solve this error.

Solution 1 : Reload required for the Python Extension

First of all, restart your Vscode and then just go to extensions view with ctrl+shift+x in Linux version. And there is a blue button. There just Reload required for the Python Extension and then restart the vscode. It will help you!

Solution 2 : Specify the location

You can solve this error very easily. Just follow this steps. First of all Click on the Your python version which is at in the corner and select your debugger or specify the location if it’s not already there. By soing this you can solve this error.

Solution 3 : Run this command

Just try the below command to solve your error completely in python.

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

Conclusion

So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.

Also Read This Solutions

  • Module not found: Error: Can’t resolve ‘fs’ in
  • Building wheel for numpy (pyproject.toml)
  • UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xff in position 0: invalid start byte
  • Incompatible JVM. Version 1.8.0_261 of the JVM is not suitable for this product. Version: 11 or greater is required in Eclipse
  • Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource

VSCode: путь Python в вашей конфигурации отладки недействителен

Очень новичок в Python и VSCode (и stackoverflow). Я использую оба уже около 3 месяцев, просто отлично, до недавнего времени.

При попытке запустить любую базовую программу Python в отладчике появляется всплывающее окно The Python path in your debug configuration is invalid. Source: Python(Extension) , и отладчик не запускается. Я захожу в свой файл launch.json и, конечно же, у меня есть путь к тому месту, где установлен Python.

Возникновение с settings.json тоже ничего не помогает, потому что у меня есть настроенный путь к Python, но отладчик по-прежнему не запускается. Я не понимаю, что здесь делать. Раньше я никогда не заходил в свои файлы .json, и мне никогда не приходилось настраивать свой путь Python после первой установки VSCode.

2 ответа

Оказалось, что мне пришлось понизить версию моего расширения Python с версии 2021.3 до 2021.2, теперь VSCode, наконец, может найти путь к Python.

Вы можете попробовать что-то подобное, но направив его туда, где ваша программа python установлена ​​в вашей системе

image

  1. press f5 to debug it
  2. message fatal:

The text was updated successfully, but these errors were encountered:

dmorris0 commented Jan 3, 2021

I’m getting the same error in VSCode under WSL with Ubuntu 20.04. It used to work fine, but I installed Python 3.7, and now it can’t find my interpreter. I even removed Python 3.7 and am getting this error.

dmorris0 commented Jan 3, 2021

Finally fixed the problem by uninstalling VSCode and reinstalling it. Now it can find the python interpreter.

scalavision commented Jan 6, 2021 •

I also encountered this, running the test from the file works fine, debugging the same test, vscode errors out with The Python path in your debug configuration is invalid , why isn’t those paths the same as a default setting? Not sure I want to reinstall vscode atm. I can’t find a way to set the pythonPath in the config. «pythonPath» shows up as not allowed .

How am I going to configure this?

karthiknadig commented Jan 6, 2021 •

@scalavision Can you share your debug configuration? Normally you don’t have to set the pythonPath in the debug configuration, unless you want to run your code using a different python.

image

you can also use «python» to set a custom python path (default uses the selected python path):

scalavision commented Jan 6, 2021

I had wrong path to python interpreter in the user settings. When manually setting the path to the interpreter via the gui, to be used inside the dev container, it silently failed. I found it in the Python log output eventually. A popup for this error would have been very helpful

[Solved] VSCode: The Python path in your debug configuration is invalid

Hello Guys, How are you all? Hope You all Are Fine. Today When I run my python code Suddenly I got VSCode: The Python path in your debug configuration is invalid in Python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How VSCode: The Python path in your debug configuration is invalid Error Occurs ?

I am trying to debug a simple python program via “F5” or “Run with debugger”. Whenever I press F5 using the python extension, a pop-up appears at the bottom right “The Python path in your debug configuration is invalid.”

How To Solve VSCode: The Python path in your debug configuration is invalid Error ?

  1. How To Solve VSCode: The Python path in your debug configuration is invalid Error ?

To Solve VSCode: The Python path in your debug configuration is invalid just Open Command Palette (Ctrl + Shift + P). Type Python: Select Interpreter, open it Select the python interpreter or enter the full path to the python interpreter.

Solution 1: add Python:Select Interpreter

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.

Solution 2: add python path in vscode

  1. See File — Preferences — Settings .
  2. Click the “Open Settings (JSON)” button. Make sure that this entry has python.exe at the end. «python.pythonPath»: «C:\Users\<your_user_name>\AppData\Local\Programs\Python\Python38\python.exe

Solution 3: add pythonPath

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

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

I tried to start Python debugging in VS Code on Windows 10 via F5 and also in the GUI-debugging menu in the top right. Yet, it always shows the following error window in the bottom right stating "The Python path in your debug configuration is invalid.":

The Python path in your debug configuration is invalid

I’m logged in a python environment related to the project called «Example«:

[email protected] MINGW64 ~/Projects
$ ls
Example  Example-venv

I activate the virtual environment (venv) like so:

[email protected] MINGW64 ~/Projects
$ source Example-venv/Scripts/activate

(Example-venv) 
[email protected] MINGW64 ~/Projects

The top-level directory tree of the «Example»-project looks like this:

Example:.
├───.git
├───.vscode
├───docs
└───src
    ├───build
    ├───config
    ├───scripts
    └───tests

The Python scripts I want to debug are located within some sub-directories of the folders «scripts» and «tests».

Now, the python.exe connected to the current venv is located here:

/c/Users/andreas.luckert/Projects/Merck-venv/Scripts/python.exe

The output of which python:

(Example-venv)
[email protected] MINGW64 ~/Projects/Example-venv/Scripts
$ which python
/c/Users/username/Projects/Example-venv/Scripts/UsersusernameProjectsExample-venv/Scripts/python

In the bottom left, I’ve chosen the correct Python interpreter path.

As for global and local settings.json, which are located at C:UsersusernameAppDataRoamingCodeUsersettings.json and C:UsersusernameProjectsExample.vscodesettings.json respectively, they have the same content (I only kept the entries related to debugging and python):

{
    // * Breadcrumbs options
    "debug.allowBreakpointsEverywhere": true,
    // * JUPYTER options
    "jupyter.sendSelectionToInteractiveWindow": true,
    // NOTE on provenance: from org-mode VS Code extension docs ("too tone")
    //  * PYTHON options
    "[python]": {
        "editor.rulers": [
            80,
            120
        ],
        "editor.defaultFormatter": "ms-python.python"
    },
    // "python.defaultInterpreterPath": "${env:PYTHON_EXE_LOC}",
    "python.defaultInterpreterPath": "/c/Users/username/Projects/Example-venv/Scripts/python.exe",
    // "python.envFile": "${workspaceFolder}${pathSeparator}.vscode${pathSeparator}vscode.env",
    "python.analysis.completeFunctionParens": true,
    "python.autoComplete.addBrackets": true,
    "python.terminal.activateEnvironment": true,
    "python.terminal.executeInFileDir": false,
    "python.terminal.launchArgs": [
        "-c",
        ""from IPython import start_ipython; start_ipython()""
    ],
    // Possible values: "Jedi", "Pylance", "Microsoft", "None".
    "python.languageServer": "Pylance",
    "python.jediMemoryLimit": 1,
    "python.linting.enabled": true,
    "python.linting.lintOnSave": true,
    "python.linting.maxNumberOfProblems": 100,
    "python.linting.ignorePatterns": [
        ".vscode/*.py",
        "**/site-packages/**/*.py"
    ],
    "python.analysis.diagnosticSeverityOverrides": {
        "reportUnusedImport": "information",
        "reportMissingImports": "none"
    },
    "python.linting.pylintPath": "C:\Users\username\Projects\Example-venv\Scripts\pylint.exe",
    "python.linting.pylintEnabled": true,
    "python.linting.pylintUseMinimalCheckers": false,
    "python.analysis.useImportHeuristic": true,
    "python.formatting.provider": "yapf",
    "python.testing.autoTestDiscoverOnSaveEnabled": true,
    "python.testing.unittestArgs": [
        "-v",
        "-s",
        ".",
        "-p",
        "*test*.py"
    ],
    "python.testing.pytestArgs": [],
}

Finally, the local launch.json located at C:UsersusernameProjectsExample.vscodelaunch.json contains the following:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            // "python": "${workspaceFolder}${pathSeparator}.vscode${pathSeparator}vscode.env",
            "python": "/c/Users/username/Projects/Example-venv/Scripts/python.exe",
            "redirectOutput": true,
            "justMyCode": false,
            "logToFile": true,
            "stopOnEntry": false,
        },
        ...
    ]
}

I’ve already tried a lot of configurations, but yet I cannot seem to get rid of the error, even though all these paths should be correct.

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • The pivot table field name is not valid ошибка
  • The pgadmin 4 server could not be contacted windows 10 ошибка