简体   繁体   English

如何从本地 windows vs 代码调试远程 python 代码

[英]how to debug remote python code from local windows vs code

I want to debug python code(on remote linux) in local windows with VS code.我想用 VS 代码在本地 windows 中调试 python 代码(在远程 linux 上)。

what i did as follows?我做了什么如下?

  1. In windows VS code, i can open remote linux python project using SSH.在 windows VS 代码中,我可以使用 Z765553E6C7AC8592C389ACB987 打开远程 linux python 项目。

  2. Installed python debug tool ptvsd both in windows and remote linux.在 windows 和远程 linux 中都安装了 python 调试工具 ptvsd。

  3. Add code below in python project import ptvsd ptvsd.enable_attach(address = ('$linux_ip', $port)) ptvsd.wait_for_attach()在 python 项目中添加以下代码 import ptvsd ptvsd.enable_attach(address = ('$linux_ip', $port)) ptvsd.wait_for_attach()

  4. project launch.json项目启动。json

    { // Use IntelliSense to learn about possible attributes. { // 使用 IntelliSense 了解可能的属性。 // Hover to view descriptions of existing attributes. // Hover 查看现有属性的描述。 // 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" } ] } ] } // 更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: Remote Attach" ,“类型”:“python”,“请求”:“附加”,“连接”:{“主机”:“$linux_ip”,“端口”:$port},“路径映射”:[{“localRoot”:“ ${workspaceFolder}", "remoteRoot": "$my_real_linux_ws" } ] } ] }

  5. start run in remote linux开始远程运行 linux

  6. add break points in vs code, and run -> start debugging, then hit an issue as follows.在 vs 代码中添加断点,然后运行 -> 开始调试,然后遇到如下问题。 I am confusing that test.py is not in dir /c4_working/test.py but in dir /c4_working/python_code/test.py.我很困惑 test.py 不在目录/c4_working/test.py 中,而是在目录/c4_working/python_code/test.py 中。 And this file is actually exist.而且这个文件是真的存在的。 So i am not sure why it want to find file in dir /c4_working/test.py?所以我不确定它为什么要在 dir /c4_working/test.py 中查找文件? How to fix it?如何解决? Thanks!谢谢!

在此处输入图像描述

Have you read the documentation before asking your question?在提出问题之前,您是否阅读过文档 A specially this part:特别是这部分: 在此处输入图像描述

PS: strongly recommend to check remote-pdb as well. PS:强烈建议也检查remote-pdb

Fixed this issue after creating a new launch.json file for this dir /c4_working/python_code.在为此目录 /c4_working/python_code 创建新的 launch.json 文件后修复了此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM