我通过 VScode 远程 ssh 连接到 HPC 环境,并希望直接在 VScode 中运行 python 代码以进行测试。我想将 python 解释器设置为一个在执行时运行 python 的奇点容器。这是通过在容器的 .def 文件中添加以下行来完成的:
%runscript
exec python
手动执行容器确实会按预期启动 python 会话。但是,在 VScode 中将 python 解释器的路径设置为容器文件时,没有任何反应。它不断询问解释器的路径,就好像没有收到任何输入一样。我尝试在 VScode GUI 中设置路径并通过在 JSON 设置文件中设置默认路径,如下所示:
{
"python.defaultInterpreterPath":"~/path/to/singularity.sif"
}
尽管这种方法在这里被报道是成功的:使用 Singularity 容器解释器的 Python 代码完成 IntelliSense https://stackoverflow.com/questions/64247615/python-code-completion-intellisense-using-singularity-container-interpreter;
那里:如何在 Visual Studio 代码中的奇点/docker 图像中使用 python 解释器 https://stackoverflow.com/questions/56764870/how-can-i-use-a-python-interpreter-in-a-singularity-docker-image-in-visual-studi .
然而,我可以选择不包含在奇点容器中的解释器,并且它工作得很好。值得注意的是,如果我将奇点容器构建为沙箱并提供沙箱中 python bin 的路径,它就会起作用。
知道这里会出什么问题吗?我在 Ubuntu 22.04 上使用最新版本的 VScode (v1.68.1) 以及远程 - SSH 扩展 (v0.82.1) 和 Python 扩展 (v2022.8.0);奇点图像是使用(v3.5.3)创建的。
我一直在尝试解决同样的问题,但找到了替代解决方案。
因此,您可以实际运行 vscode server,而不是在主机上运行 vscode serverinside主机上的奇点容器。以下程序是从这条评论 https://github.com/microsoft/vscode-remote-release/issues/3066#issuecomment-1019500216作者:@oschulz github 用户。
- 确保您的 vscode 版本 >= v1.64。
- Put
"remote.SSH.enableRemoteCommand": true
在你的 vscode 中settings.json
- 在您的本地计算机中,添加如下内容
$HOME/.ssh/config
Host myimage1~*
RemoteCommand singularity shell /path/to/image1.sif
RequestTTY yes
Host somehost myimage1~somehost
HostName some.host.somewhere
User your_username_
- 测试它是否有效:尝试
ssh myimage1~somehost
和类似的东西python3 --version
- 将其添加到您的
settings.json
:
"remote.SSH.serverInstallPath": {
"myimage1~somehost": "~/.vscode-container/myimage1",
}
- 在 vscode 中,使用 RemoteSSH 连接到主机,将主机名指定为
myimage1~somehost
.
你可能想要Kill VS Code Server On Host...
如果有什么东西不工作。只需在 vscode 命令面板中输入“kill”即可。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)