我将我的远程(ubuntu 16.04)驱动器安装在我的本地系统(ubuntu 16.04)上,这样我就可以通过在 vscode 中打开它们来编辑源文件。
此外,在集成终端中,我可以通过 ssh 连接到远程系统并使用安装在虚拟环境中的远程 python 解释器运行程序,例如:
$ssh username@remoteip
$workon remotevirtualenv
(remotevirtualenv)$python source.py
我想启用远程调试,这样如果我运行调试/运行远程文件,安装在我本地系统上的 vscode 就会使用我的远程 python 解释器。
我浏览了建议使用 ptvsd 扩展的文档(它要求在本地有 2 个源文件副本,另一个在服务器上),但我不确定如何在这种情况下配置它。 感谢帮助。谢谢。
编辑 1: 正如我所说,我已经阅读了文档,但我不清楚如何在这种情况下进行配置。例如文档说
- In the source code on both computers, add the following lines, replacing my_secret with the appropriate passphrase to authenticate remote debugging, and replacing address with the appropriate IP address (or localhost) and port number:
ptvsd.enable_attach("my_secret", address = ('0.0.0.0', 3000))
但我只有一份源文件副本,即在远程系统上。我刚刚将它安装在我的本地文件系统上。因此,我应该提供我的本地 ip 地址还是应该是远程系统 ip 以及我应该使用哪个端口号,因为我只有一个源副本和 ptvsd,它将如何通信。
另外,在配置中,我应该为 localRoot
位置和 remoteRoot
位置使用什么。
3. {
"name": "Attach (Remote Debug)",
"type": "python",
"request": "attach",
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"port": 3000,
"secret": "my_secret",
"host": "localhost"
}
编辑:由于 VSCode 中的远程开发扩展,现在远程调试非常容易。
最佳答案
您需要将远程 ip 地址放在 ptvsd.enable_attach("my_secret", address = ('remote_ip_address', 3000))
和 launch.json
中:
{
"name": "Attach (Remote Debug)",
"type": "python",
"request": "attach",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/home/user1/scripts/",
"port": 3000,
"secret": "my_secret",
"host": "remote_ip_address"
}
您还需要将 remoteRoot
值更改为脚本在远程计算机中所在目录的路径(例如 /home/user1/scripts/
) .
最后,打开一个 ssh 连接:ssh -L 3000:localhost:3000
,在远程机器上运行你的脚本,并在本地机器上附加调试器。
关于python - 在 VSCode 中设置 Python 远程调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47809545/