简体   繁体   中英

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.

what i did as follows?

  1. In windows VS code, i can open remote linux python project using SSH.

  2. Installed python debug tool ptvsd both in windows and remote linux.

  3. Add code below in python project import ptvsd ptvsd.enable_attach(address = ('$linux_ip', $port)) ptvsd.wait_for_attach()

  4. project 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" } ] } ] }

  5. start run in remote linux

  6. add break points in vs code, and run -> start debugging, then hit an issue as follows. I am confusing that test.py is not in dir /c4_working/test.py but in dir /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? 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.

Fixed this issue after creating a new launch.json file for this dir /c4_working/python_code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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