【问题标题】:python scripts debug in ROS with Visual Studio Code使用 Visual Studio Code 在 ROS 中调试 python 脚本
【发布时间】:2018-05-22 01:25:25
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    VSCode enables you to do this by settingpreLaunchTask 在你的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
            }
        ]
    }
    

    记住标签“预运行”。现在在你的launch.jsonalt Launch configuration,将此标签设置为preLaunchTasklike

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

    【讨论】:

    • 谢谢。你的方法完美解决了我的问题。 :)
    • 很高兴能帮上忙。也许,您可以将此标记为答案@JoeyChia?
    • 可以。但是我对stackoverflow的mark函数不熟悉。您是指答案左侧的复选标记吗?
    • @JoeyChia 是的。就是这样!
    • 当我这样做时,(preLaunch) 任务和 python 文件在单独的终端中执行,所以采购没有效果。如何解决这个问题?
    猜你喜欢
    • 2018-12-17
    • 2015-10-04
    • 2021-02-01
    • 2021-03-05
    • 2023-03-11
    • 2022-10-22
    • 1970-01-01
    • 2020-05-07
    • 2018-10-21
    相关资源
    最近更新 更多