问题描述
我尝试用定义文件nnunet.def
扩展pytorch docker image:
Bootstrap: docker
From: pytorch/pytorch:1.4-cuda10.1-cudnn7-runtime
%post
git clone https://github.com/NVIDIA/apex
cd apex
pip install -v --no-cache-dir ./
%runscript
echo "Running nnunet container..."
但是,当我使用sudo singularity build image.sif nnunet.def
构建此图像时,出现一个错误,提示未找到pip:
...
+ pip install -v --no-cache-dir ./
/.build-script-post: 6: /.build-script-post: pip: not found
FATAL: failed to execute %post proc: exit status 127
FATAL: While performing build: while running engine: while running /usr/local/libexec/singularity/bin/starter: exit status 255
为什么?
更令人惊讶的是,当我直接从该图像输入外壳程序时:
singularity shell docker://pytorch/pytorch:1.4-cuda10.1-cudnn7-runtime
我使用pip没问题:
Singularity> pip freeze
asn1crypto==1.2.0
backcall==0.1.0
...
为什么我不能在定义文件的%post
部分中使用pip?
解决方法
简短的回答:$PATH
中%post
的值与您在shell中运行时的值不同,因此它不知道在哪里查看。
如果您查看docker或奇异映像中pip的位置(which pip
),则它位于/opt/conda/bin/pip
。 %post
中使用的默认路径为/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
。
当您看到一条错误消息,指出作为脚本的一部分运行时命令不可用,而当您以交互方式运行时,则几乎总是环境问题,PATH
,PYTHONPATH
, PERL5LIB
等是罪魁祸首。
如果将export PATH=/opt/conda/bin:$PATH
添加到%post
块的开头,它将解决此问题。