在Visual Studio代码中使用奇异容器作为Python解释器

发布于 2025-02-10 21:00:58 字数 1150 浏览 3 评论 0原文

我通过VSCODE远程SSH连接到HPC环境,并希望直接在VSCODE中运行Python代码以进行测试。我想将Python解释器设置为一个奇异的容器,该容器在执行后运行Python。这是通过在容器的.def文件中添加以下行来完成的:

%runscript
  exec python

手动执行容器确实按预期启动Python会话。但是,将Python解释器的路径设置为VSCODE中的容器文件时,什么都不会发生。它不断要求解释器的路径,好像没有收到任何输入。我试图在VSCODE GUI中设置路径,并通过设置JSON设置文件中的默认路径这样:

{
    "python.defaultInterpreterPath":"~/path/to/singularity.sif"
}

尽管此方法在这里成功地报告了: Python代码完成Intellion Intellion Intellion Intellion Intellisense使用Singularity Contulity Containser Interner Interner ; 在那里: 如何?我在Visual Studio代码中使用奇异性/Docker图像中使用Python解释器

但是,我可以选择不包含在奇点容器中的口译器,并且效果很好。值得注意的是,如果我将奇点容器作为沙盒构建,并为沙盒中的Python垃圾箱提供了路径。

知道这里有什么问题吗?我将最新版本的VSCODE(v1.68.1)与Ubuntu 22.04上的遥控器-SSH扩展(v0.82.1)和Python扩展(v2022.8.0)一起使用;用(v3.5.3)创建了奇异图像。

I am connecting to an HPC environment through VScode remote ssh and would like to run python code directly in VScode for testing purposes. I would like to set the python interpreter to a singularity container which runs python upon execution. This was done by adding the following lines in the .def file of the container:

%runscript
  exec python

Executing the container manually does start a python session as intended. However, nothing happens when setting the path of the python interpreter to the container file in VScode. It keeps asking for the path of the interpreter as if it did not receive any input. I tried to set the path both in VScode GUI and by setting the default path in the JSON settings file like so:

{
    "python.defaultInterpreterPath":"~/path/to/singularity.sif"
}

Although this approach was reported successful here:
Python code completion IntelliSense using Singularity container interpreter ;
and there:
How can I use a python interpreter in a singularity/docker image in visual studio code .

I can however select interpreters that are not contained in singularity containers and it works fine. Notably, it works if I build the singularity container as a sandbox and provide a path to the python's bin in the sandbox.

Any idea what could go wrong here? I am using the latest version of VScode (v1.68.1) with the the Remote - SSH extension (v0.82.1) and Python extension (v2022.8.0) on Ubuntu 22.04; singularity images were created with (v3.5.3).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海的爱人是光 2025-02-17 21:00:58

我一直在尝试解决同一问题,但找到了另一种解决方案。

因此,您实际上可以在主机上运行vscode Server 主机上的奇异容器,而不是在主机上运行VSCODE服务器。从此评论 Oschulz github用户。

  1. 确保您拥有VSCODE版本> = V1.64。
  2. 放入vscode的 settings.json 中的 true 中的“ remote.ssh.ssh.ssh.ssh.ssh.ssh.ssh.ssh.ssh.ssh.ssh.ssh.ssh.ssh.json
Host myimage1~*
  RemoteCommand singularity shell /path/to/image1.sif
  RequestTTY yes

Host somehost myimage1~somehost
  HostName some.host.somewhere
  User your_username_
  1. 测试它正在工作:尝试ssh myimage1〜Some -Host以及类似python3 -version之类的东西,
  2. 将其添加到您的settings.json.json
"remote.SSH.serverInstallPath": {
  "myimage1~somehost": "~/.vscode-container/myimage1",
}
  1. 在VSCODE中,使用remotessh连接到主机,将主机名指定为myimage1〜some -Host

您可能需要在主机上杀死VS代码服务器...如果某些内容不起作用。只需在Vscode的命令Palete中键入“ Kill”。

I have been trying to solve the same issue but found an alternative solution.

So instead of running vscode server on the host, you can actually run vscode server inside the singularity container on the host. The following procedure is cut from this comment by @oschulz github user.

  1. Make sure you have vscode version >= v1.64.
  2. Put "remote.SSH.enableRemoteCommand": true in your vscode's settings.json
  3. In your local machine, add something like below to $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_
  1. Test that it's working: try ssh myimage1~somehost and something like python3 --version
  2. Add this to your settings.json:
"remote.SSH.serverInstallPath": {
  "myimage1~somehost": "~/.vscode-container/myimage1",
}
  1. In vscode, connect to host using RemoteSSH, specify hostname as myimage1~somehost.

You might want to Kill VS Code Server On Host... if something is not working. Just type "kill" in vscode's command palete.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文