I want to debug python code (on remote linux) in local windows with VS code.
I did as follows:
- In windows VS code, I can open remote linux python project using SSH.
- Installed python debug tool ptvsd both in windows and remote linux.
- Add code below in python project:
JavaScript
x
4
1
import ptvsd
2
ptvsd.enable_attach(address = ('$linux_ip', $port))
3
ptvsd.wait_for_attach()
4
- Project
launch.json
:
JavaScript
1
24
24
1
{
2
// Use IntelliSense to learn about possible attributes.
3
// Hover to view descriptions of existing attributes.
4
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
"version": "0.2.0",
6
"configurations": [
7
{
8
"name": "Python: Remote Attach",
9
"type": "python",
10
"request": "attach",
11
"connect": {
12
"host": "$linux_ip",
13
"port": $port
14
},
15
"pathMappings": [
16
{
17
"localRoot": "${workspaceFolder}",
18
"remoteRoot": "$my_real_linux_ws"
19
}
20
]
21
}
22
]
23
}
24
- Start run in remote linux.
- Add break points in vs code, and run -> start debugging, then hit an issue as follows. I am confused that test.py is not in dir
/c4_working/test.py
but in dir/c4_working/python_code/test.py
. And this file actually exists. So I am not sure why it would want to find the file in dir/c4_working/test.py
? How would I fix it?
Advertisement
Answer
Fixed this issue after creating a new launch.json file for this dir /c4_working/python_code.