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).

majpark
  • 83
  • 9
  • There seems to be a similar [issue](https://stackoverflow.com/questions/56764870/how-can-i-use-a-python-interpreter-in-a-singularity-docker-image-in-visual-studi). I think this method should be effective – MingJie-MSFT Jun 28 '22 at 02:42
  • Thank you, but this is actually exactly what I have tried. EDIT: I actually wanted to link this issue in my question, but got things mixed up, it's now corrected. Sorry! – majpark Jun 28 '22 at 08:08
  • Not a lot to go on. Are there any error messages in vs code in `output` -> `Python`? – tsnowlan Jun 28 '22 at 12:31
  • Unfortunately no, no message whatsoever in any output category. – majpark Jun 28 '22 at 15:07

1 Answers1

2

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.

Juno
  • 31
  • 1