python 脚本在 ROS 中使用 Visual Studio 代码进行调试
python scripts debug in ROS with Visual Studio Code
为了调试 python 脚本,我想在 python 调试器开始之前 运行 "source path_to/setup.bash"。我应该怎么做?谢谢!
VSCode enables you to do this by setting preLaunchTask
在你的 launch.json
您需要 task.json
,type
设置为 shell
。它看起来像这样。
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
}
]
}
记住标签"prerun"。现在在您的 launch.json
、alt Launch configuration 中,将此标签设置为 preLaunchTask
like
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"
},
]
}
您可以根据需要定制调试配置。对于上面的示例,每次 Python 源文件是编辑器处于调试状态时,它都会预启动 hello.sh
。现在切换到您的 Python 代码并继续调试。希望这有帮助。
为了调试 python 脚本,我想在 python 调试器开始之前 运行 "source path_to/setup.bash"。我应该怎么做?谢谢!
VSCode enables you to do this by setting preLaunchTask
在你的 launch.json
您需要 task.json
,type
设置为 shell
。它看起来像这样。
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
}
]
}
记住标签"prerun"。现在在您的 launch.json
、alt Launch configuration 中,将此标签设置为 preLaunchTask
like
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"
},
]
}
您可以根据需要定制调试配置。对于上面的示例,每次 Python 源文件是编辑器处于调试状态时,它都会预启动 hello.sh
。现在切换到您的 Python 代码并继续调试。希望这有帮助。