0
votes

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

username@hd1pcms0347 MINGW64 ~/Projects
$ ls
Example  Example-venv

I activate the virtual environment (venv) like so:

username@hd1pcms0347 MINGW64 ~/Projects
$ source Example-venv/Scripts/activate

(Example-venv) 
username@hd1pcms0347 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)
username@hd1pcms0347 MINGW64 ~/Projects/Example-venv/Scripts
$ which python
/c/Users/username/Projects/Example-venv/Scripts/\Users\username\Projects\Example-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:\Users\username\AppData\Roaming\Code\User\settings.json and C:\Users\username\Projects\Example\.vscode\settings.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:\Users\username\Projects\Example\.vscode\launch.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.

1

1 Answers

0
votes

Putting

"python.defaultInterpreterPath": "C:\\Users\\username\\Projects\\Example-venv\\Scripts\\python.exe"

in my global and local settings.json and

"python": "C:\\Users\\username\\Projects\\Example-venv\\Scripts\\python.exe"

in my local launch.json has resolved the issue. This is surely due to the fact that Windows requires backslashes and moreover they need to be escaped by backslashes themselves, therefore the double-"".

Yet, this does not seem to be the most elegant solution to the entire set-up. If someone has a better set-up idea, please feel free to post an answer.