Start debugging Python from CLI with VSCode
Debugging configurations for Python apps in Visual Studio Code
launch.json を頑張って書かずに、普通に command line から Python を実行してそれに VSCode の debugger を attach する方法。 visually に debug できるわけではないようなのでそんなに便利じゃないかも。 (pdb や ipdb + Emacs or vi のがよいかも)
code:sh
python -m debugpy --listen 5678 ./myscript.py
のように起動してから、 VSCode の debugger から attach するようにすれば良い。 VSCode の launch.json は以下のようにすれば良い。 remote の場合は localhost の部分を書き換えればいけるはず。
code:json
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
}
}
debugpy は pip install debugpy, conda install debugpy などで入る。
--wait-for-client option をつけると debugger が attach するまで実行を待ってくれる
#VSCode #Python