4

I want to be able to use a python interpreter inside a singularity image from visual studio code.

It seems that all of the options to point VSC to python interpreters involve a direct path, but using python within an image requires a command:

singularity exec path/to/image.img python3.6

I tried putting this in the VSC settings.json file:

    "[python]": {
        "python.pythonPath": "singularity exec /home/sryadgir/all/docker/py_dock/pydock_v0.img python3.6"
    }

with no luck, running any python code from VSC uses the python interpreter here: /usr/bin/python3

1 Answers1

4

The easiest way is to use the singularity image's runscript and set "python.pythonPath": "path/to/python.img" e.g.,

$ sudo singularity build py36.simg docker://python:3.6 
Docker image path: index.docker.io/library/python:3.6
Cache folder set to /root/.singularity/docker
[9/9] |===================================| 100.0% 
Importing: base Singularity environment
Exploding layer: sha256:6f2f362378c5a6fd915d96d11dda1e0223ccf213bf121ace56ae0f6616ea1dc8.tar.gz
Exploding layer: sha256:494c27a8a6b820f9167ec7e368b3a9bb47d7029f4dc8c97c67091f3757a5bc4e.tar.gz
Exploding layer: sha256:7596bb83081b6c8410df557d538a0ae45922cbf81e469c6f4cfa835247cb24ab.tar.gz
Exploding layer: sha256:372744b62d49eba993652ee4a1201801fe278b687d85489101e07e7b9a4900e0.tar.gz
Exploding layer: sha256:615db220d76c063138a2e6c5849703a7a80d682a682f7e1a841e6e7ed5f43879.tar.gz
Exploding layer: sha256:1865698adfb04b47d1aa53e0f8dac0a511d78285cb4dda39b4f3b0b3b091bb2e.tar.gz
Exploding layer: sha256:7159b3304cc0ff68a7903c2660aa37fdae97a02164449400c6ef283a6aaf3879.tar.gz
Exploding layer: sha256:ad0713808ef687d1e541819f50497506f5dce12604d1af54dbae153d61d5cf21.tar.gz
Exploding layer: sha256:7ba59390457320287875a9c381fee7936b50ecfd21abfe3c50278ac2f39b9786.tar.gz
Exploding layer: sha256:14b2fefd5f8a77dd860f2f455a2108a55836dd0062ced0df5fbd636ce3188ff7.tar.gz
Building Singularity image...
Singularity container built: py36.simg
Cleaning up...

$ ./py36.simg --version
Python 3.6.8
# this is equivalent to:
$ singularity exec py36.simg python3 --version
Python 3.6.8

If you're using a custom singularity image with multiple versions of python, you'll probably need to make a wrapper script and then use that. e.g.,

#!/bin/bash

exec singularity exec python.img python3.6 "$@"
tsnowlan
  • 3,472
  • 10
  • 15