[英]python scripts debug in ROS with Visual Studio Code
In order to debug python scripts, I would like to run "source path_to/setup.bash" before python debugger begins. 为了调试python脚本,我想在python调试器开始之前运行“ source path_to / setup.bash”。 How should I to do so ? 我应该怎么做? Thank you! 谢谢!
VSCode enables you to do this by setting a preLaunchTask
in your launch.json
VSCode使您可以通过在preLaunchTask
中设置 preLaunchTask
来执行此 launch.json
What you need is a task.json
with a type
set to shell
. 您需要的是一个task.json
,其type
设置为shell
。 It looks something like this. 看起来像这样。
task.json task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "prerun",
"type": "shell",
"command": "source hello.sh" // your shell command here
}
]
}
Remember the label "prerun". 记住标签“ prerun”。 Now in your launch.json
, alt Launch configuration , set this label as preLaunchTask
like 现在在launch.json
, alt 启动配置中 ,将此标签设置为preLaunchTask
例如
launch.json launch.json
{
// 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 Experimental: Current File (Integrated Terminal)",
"type": "pythonExperimental",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"preLaunchTask": "prerun"
},
]
}
You can tailor your debug configuration for your needs. 您可以根据需要定制调试配置。 For the example above, it pre-launches hello.sh
every time Python source file is the editor is in debug. 对于上面的示例,每次在Python源文件作为编辑器处于调试状态时,它都会预启动hello.sh
。 Now switch to your Python code and continue debugging. 现在切换到您的Python代码并继续调试。 Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.