前言
如题。我在命令行运行的是python3 -m sosed.run -i input_examples/input.txt -o output/closure/
,但是在VSCode中的普通调试,会报模块找不到的问题(原因是普通调试不会带-m参数,所以有些路径就会找不到)。因此,本文记录如何用VSCode调试在命令行输入的如上Python指令。
场景简介
我调试的Python程序是sosed工具,见:https://github.com/JetBrains-Research/sosed
不多说,直接讲方案。简洁也快捷。
解决方案
在命令行:
# 先按照这个module
python3 -m pip install debugpy
# 在命令行运行:
python3 -m debugpy --listen 5678 --wait-for-client -m sosed.run -i input_examples/input.txt -o output/closure/
而后在VSCode中,点击:上方菜单栏->debug->Open Configurations
,修改内容为如下:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
}
}
]
}
然后按下Ctrl + F5
,debug的快捷键(记得提前设置断点),就可以开始调试了。
参考:
小结
还行,这次挺快。速战速决。