【发布时间】:2021-09-13 17:46:46
【问题描述】:
我尝试通过F5 在Windows 10 上的VS Code 以及右上角的GUI 调试菜单中启动Python 调试。然而,它总是在右下角显示以下错误窗口,说明"The Python path in your debug configuration is invalid.":
我登录了一个与名为“Example”的项目相关的python环境:
username@hd1pcms0347 MINGW64 ~/Projects
$ ls
Example Example-venv
我像这样激活虚拟环境(venv):
username@hd1pcms0347 MINGW64 ~/Projects
$ source Example-venv/Scripts/activate
(Example-venv)
username@hd1pcms0347 MINGW64 ~/Projects
“示例”项目的顶级目录树如下所示:
Example:.
├───.git
├───.vscode
├───docs
└───src
├───build
├───config
├───scripts
└───tests
我要调试的 Python 脚本位于文件夹“scripts”和“tests”的一些子目录中。
现在,连接到当前venv的python.exe位于这里:
/c/Users/andreas.luckert/Projects/Merck-venv/Scripts/python.exe
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
在左下角,我选择了正确的 Python 解释器路径。
至于全局和本地settings.json,分别位于C:\Users\username\AppData\Roaming\Code\User\settings.json和C:\Users\username\Projects\Example\.vscode\settings.json,内容相同(我只保留了调试和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": [],
}
最后,位于C:\Users\username\Projects\Example\.vscode\launch.json 的本地launch.json 包含以下内容:
{
"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,
},
...
]
}
我已经尝试了很多配置,但我似乎无法摆脱错误,即使所有这些路径都应该是正确的。
【问题讨论】:
标签: python-3.x visual-studio-code vscode-settings vscode-debugger pythonpath