使用 Visual Studio Code 在 ROS 中调试 python 脚本

标签 python ros visual-studio-code vscode-debugger

为了调试 python 脚本,我想在 python 调试器开始之前运行“source path_to/setup.bash”。我应该怎样做呢?谢谢!

最佳答案

VSCode enables you to do this by setting launch.json

中的 preLaunchTask

您需要的是一个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
        }
    ]
}

记住标签“预运行”。现在在您的 launch.json 中,alt Launch configuration ,将此标签设置为 preLaunchTask 就像

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 代码并继续调试。希望这会有所帮助。

关于使用 Visual Studio Code 在 ROS 中调试 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50458542/

相关文章:

python - 如何在 Django、Varnish、Nginx 中处理数千个遗留 URL?

python - 字符\u260e

node.js - Pop-OS/Ubuntu 更新后找不到模块 '../build/Release/zmq.node'

c++ - 使用 nonfree/feature2d.hpp 的 OpenCV 编译错误

python - 在jetson xavier nx上安装python2的llvmlite和numba库

ubuntu - 在 Ubuntu 下使用 Visual Studio Code 显示错误

visual-studio - 如何在 Visual Studio 中使用 Rational Team Concert 配置 Visual Studio 代码合并工具?

python - 如何使用参数渲染基于文件的模板?

python - 如何在 RDKit 中以 SVG(高分辨率)形式突出显示带有粗红线的分子的子结构

c++ - 在 CLion 中设置 ROS 包