首页 > 解决方案 > 如何在本地vscode中调试远程服务器上的python文件

问题描述

我可以通过 ssh 连接到我的远程服务器

$ssh -p ${port}root@${remoteIpAddress}

我在本地vscode中编辑源代码,并在安装了conda环境的远程服务器上运行我的项目,另外,我的本地电脑没有安装conda,也没有远程服务器的源代码。它工作得很好,但现在我想使用 vscode 的调试器在远程服务器中调试我的代码。我已经阅读了几个答案并创建了一个这样的 launch.json 文件:

{
"name": "Attach (Remote Debug)",
"type": "python",
"request": "attach",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/my_project/project_name",
"port": ${port},
"secret": "my_secret",
"host": "localhost" 
}

我运行项目

./file_name.sh --inference --checkpoint ${path_to_checkpoint} 0

并点击运行和调试按钮。它向我显示了这样的错误:

cd /run/user/10086/gvfs/sftp:host=${IpAdress},port=${port},user=root/root/my_project ; /usr/bin/env /bin/python3 /home/MyFolder/vietnt39/.vscode/extensions/ms-python.python-2021.9.1191016588/pythonFiles/lib/python/debugpy/launcher 45201 -- /run/user/10086/gvfs/sftp:host=${IpAddress},port=${port},user=root/root/my_project/project_name/src/experiments.py 
-bash: ./file_name.sh: No such file or directory
/usr/bin/env: ‘/bin/python3’: No such file or directory

谁能知道这样做的正确方法?请帮我。我真的很感激!

标签: visual-studio-codesshremote-debugging

解决方案


推荐阅读