本文介绍了如何在使用bazel构建的项目中使用vscode python调试器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想调试一个Python文件,该文件具有一些依赖性,这些依赖性仅出现在bazel的 runfiles
中.如何使用vscode调试器调试bazel版本?
I want to debug a python file which has a few dependencies that only appear in the runfiles
from bazel. How can I debug a bazel build with the vscode debugger?
推荐答案
有名的人说:是的,我们可以."
As someone famous said, "Yes, we can".
您将需要使用"ptvsd" python软件包.
You would need to use the "ptvsd" python package.
- 在Bazel中将"ptvsd"添加为Python依赖项
- 在VS Code中,在您的
launch.json
文件中,添加以下配置:
- Add "ptvsd" as a Python dependency in Bazel
- In VS Code, in your
launch.json
file, add the following configuration:
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"port": 5724,
"host": "localhost"
},
调试
要调试特定文件时:
Debug
When you want to debug a specific file:
- 在要调试的Python文件中,添加以下行:
import ptvsd
ptvsd.enable_attach(address=('localhost', 5724), redirect_output=True)
print('Now is a good time to attach your debugger: Run: Python: Attach')
ptvsd.wait_for_attach()
- 像往常一样在此文件上运行Bazel(例如, bazel运行:server )
- 执行将停止在现在是连接调试器的好时机:运行:Python:附加"
- 在VS Code中,单击我们之前设置的"Python:附加"调试选项:
- 就是这样!
随意更改端口,在此示例中为5724.
Feel free to change the port, 5724 in this example.
这篇关于如何在使用bazel构建的项目中使用vscode python调试器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!