在VSCode中调试Django在 imp.py 失败



我无法调试我的 Django 应用程序。我正在使用 virtualenv,并将我的 VSCode 工作区配置为指向我的 python 虚拟环境中的绝对路径。

"python.pythonPath": "/Users/Me/PyProjs/proj_env/bin/python"

但是,当尝试调试时,编辑器会跳转到 imp.py 文件(位于 ~/proj_env/lib/python3.4(,并在new_module()方法处失败。

def new_module(name):
"""**DEPRECATED**
Create a new module.
The module is not entered into sys.modules.
"""
return types.ModuleType(name) #Editor breaks here.

检查name变量,我看到它设置为"__main__".单步执行时,编辑器退出调试模式,并且调试控制台中不会记录任何错误或异常。

有人知道我的问题可能是什么吗?我只想调试我的应用程序!

你可能在launch.json中将stopOnEntry设置为true。 尝试将其设置为 false:

{
"name": "Python: Django",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceFolder}/manage.py",
"cwd": "${workspaceFolder}",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput",
"DjangoDebugging"
]
},

看起来像一个可能的缺陷,检查 VS Code Python GitHub 存储库:https://github.com/DonJayamanne/pythonVSCode/issues/1092

最新更新