如何在Visual Studio代码的奇异性/ docker图像中使用python解释器

时间:2019-06-26 03:45:17

标签: python-3.x docker vscode-settings singularity-container

我希望能够在Visual Studio代码的奇异图像内使用python解释器。

似乎所有将VSC指向python解释器的选项都涉及直接路径,但是在图像中使用python则需要一个命令:

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

我尝试将其放入VSC settings.json文件中

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

没有运气,从VSC运行任何python代码都在这里使用python解释器:/usr/bin/python3

1 个答案:

答案 0 :(得分:0)

最简单的方法是使用奇异图像的运行脚本并设置"python.pythonPath": "path/to/python.img",例如

$ 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

如果您正在使用具有多个python版本的自定义奇点图像,则可能需要制作一个包装脚本,然后使用它。例如,

#!/bin/bash

exec singularity exec python.img python3.6 "$@"