我回答了我自己的问题,请参阅下面的解决方案。把这一切留在这里留给后代,因为我做了很多其他人认为可行并为他们工作的事情,但没有一个奏效。
下面是一个非常简单的python文件。当试图在这个文件上使用 Visual Studio Code 的调试器时,我总是ImportError在任何内部模块上得到一个,比如app.models或app.tests.scripts.stubs。如果这些模块在下面列出faker,或任何其他外部模块,调试器将通过外部模块而不会抛出错误,但会在app.models或首先列出的任何内部模块上抛出错误。在我尝试过的 8-10 个文件中确实如此。
我已经在 launch.json 和 User Settings 中指定了确切的 pythonPath,如下所示。我添加"exceptionHandling"了忽略ImportErrors。我已经卸载并重新安装了 Don Jayamanne 出色的 Python 扩展。我碰到的Python: Select Workspace Interpreter,并指出它./.venv/bin/python2.7,./.venv/bin/python2和``./。VENV /斌/ python`。
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "/Users/REDACTED/REDACTED/.venv/bin/python2.7",
"program": "${file}",
"cwd": "${workspaceRoot}",
"env": null,
# we have 10+ environmental shell scripts, so I can't really use "envFile" in
# …Run Code Online (Sandbox Code Playgroud) visual-studio-debugging python-2.7 visual-studio-code vscode-settings