【发布时间】:2021-05-11 18:57:50
【问题描述】:
我想用 VS 代码在本地窗口中调试 python 代码(在远程 linux 上)。
我做了如下:
- 在 windows VS 代码中,我可以使用 SSH 打开远程 linux python 项目。
- 在 windows 和远程 linux 中都安装了 python 调试工具 ptvsd。
- 在python项目中添加以下代码:
import ptvsd
ptvsd.enable_attach(address = ('$linux_ip', $port))
ptvsd.wait_for_attach()
- 项目
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"
}
]
}
]
}
- 开始在远程 linux 中运行。
- 在 vs 代码中添加断点,然后运行 -> 开始调试,然后遇到如下问题。我很困惑 test.py 不在目录
/c4_working/test.py中,而是在目录/c4_working/python_code/test.py中。而且这个文件确实存在。所以我不确定它为什么要在目录/c4_working/test.py中找到文件?我该如何解决?
【问题讨论】:
标签: python debugging visual-studio-code