【问题标题】:How to debug remote python code from local windows vs code如何从本地窗口与代码调试远程 python 代码
【发布时间】:2021-05-11 18:57:50
【问题描述】:

我想用 VS 代码在本地窗口中调试 python 代码(在远程 linux 上)。

我做了如下:

  1. 在 windows VS 代码中,我可以使用 SSH 打开远程 linux python 项目。
  2. 在 windows 和远程 linux 中都安装了 python 调试工具 ptvsd。
  3. 在python项目中添加以下代码:
import ptvsd
ptvsd.enable_attach(address = ('$linux_ip', $port))
ptvsd.wait_for_attach() 
  1. 项目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: Remote Attach",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "$linux_ip",
                "port": $port 
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "$my_real_linux_ws"
                }
            ]
        }
    ]
}
  1. 开始在远程 linux 中运行。
  2. 在 vs 代码中添加断点,然后运行 ​​-> 开始调试,然后遇到如下问题。我很困惑 test.py 不在目录/c4_working/test.py 中,而是在目录/c4_working/python_code/test.py 中。而且这个文件确实存在。所以我不确定它为什么要在目录/c4_working/test.py 中找到文件?我该如何解决?

【问题讨论】:

    标签: python debugging visual-studio-code


    【解决方案1】:

    您在提问之前阅读过documentation 吗? 特别是这部分:

    PS:强烈建议也检查remote-pdb

    【讨论】:

      【解决方案2】:

      在为此目录 /c4_working/python_code 创建新的 launch.json 文件后修复了此问题。

      【讨论】:

        猜你喜欢
        • 2018-11-19
        • 2011-06-17
        • 2022-11-15
        • 1970-01-01
        • 2020-12-03
        • 2014-03-16
        • 2016-01-22
        • 2015-05-26
        • 2020-04-26
        相关资源
        最近更新 更多