【发布时间】:2017-11-28 14:40:29
【问题描述】:
我正在尝试使用 VSCode-Python 扩展从 VSCode 调试 python flask 应用程序。根据两个文档,有两种方法可以使其工作:
- 在 launch.json 中使用
"module":"flask.cli"选项 - 使用导入
flask.cli模块的启动脚本。描述here
对于这两种方式,我最终都会得到:OSError: Windows error 1。这似乎是一个错误,表明从flask.cli 导入的main 函数不存在。
我正在使用 virtualenv。如果我尝试从命令行运行,应用程序运行正常。
这是 settings.json 的内容(env 是包含环境脚本的文件夹):
{
"python.pythonPath": "${workspaceRoot}\\backend\\env\\Scripts\\python.exe"
}
这是launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Flask (0.11.x or later)",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"cwd": "${workspaceRoot}",
"module":"flask.cli",
"env": {
"FLASK_APP": "${workspaceRoot}\\backend\\app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
}
]
}
这是完整的错误堆栈跟踪:
runpy.py:125: RuntimeWarning: 'flask.cli' found in sys.modules after import of package 'flask', but prior to execution of 'flask.cli'; this may result in unpredictable behaviour
warn(RuntimeWarning(msg))
line 205, in run_module return _run_module_code(code, init_globals, run_name, mod_spec)
line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name)
line 85, in _run_code exec(code, run_globals)
line 517, in <module> main(as_module=True)
line 513, in main cli.main(args=args, prog_name=name)
line 380, in main return AppGroup.main(self, *args, **kwargs)
line 707, in main e.show()
line 47, in show echo(self.ctx.get_usage() + '\n', file=file, color=color)
line 259, in echo file.write(message)
line 180, in write return self._text_stream.write(x)
line 164, in write raise OSError(self._get_error_message(GetLastError()))
OSError: Windows error 1
【问题讨论】:
标签: python flask visual-studio-code