3 nipype conda singularity-container
我有以下奇点容器配方:
#!/bin/bash
Bootstrap: docker
From: nipype/nipype:latest
%labels
Version v1.0
%post
# Install nano
apt-get update
apt-get install nano
# Set up Python environment
CONDA_ENV=/opt/conda/bin
export PATH=$CONDA_ENV:$PATH
chmod -R 777 $CONDA_ENV
# Activate conda environment
conda activate neuro
conda install seaborn
pip install pybids
Run Code Online (Sandbox Code Playgroud)
我用 Singularity 构建容器,如下所示:
sudo singularity build swish.simg Singularity.swish
依赖项的安装和大部分构建都进展顺利,直到我遇到错误source not found。重申一下这个问题和我所尝试过的:
小智 5
问题归结于您激活环境的方式。通常,你会这样做:
source /opt/conda/bin/activate neuro
Run Code Online (Sandbox Code Playgroud)
但如果 Singularity 容器帖子是在 shell (sh) 环境中构建的,则预计您将找不到该source命令。相反,你想做的是:
. /opt/conda/bin/activate neuro
Run Code Online (Sandbox Code Playgroud)
然后你就不需要大惊小怪了$PATH。您也不需要在文件顶部指定解释器。所以整个食谱应该是这样的:
Bootstrap: docker
From: nipype/nipype:latest
# This is the adjusted (fixed) build recipe for the issue above.
# sudo singularity build swist Singularity.swist
%labels
Version v1.0
%environment
. /opt/conda/bin/activate neuro
%post
# Install nano
apt-get update && apt-get install -y nano
# Install into conda environment
. /opt/conda/bin/activate neuro &&
/opt/conda/bin/conda install --name neuro -y seaborn &&
/opt/conda/envs/neuro/bin/pip install pybids
Run Code Online (Sandbox Code Playgroud)
然后用法是:
sudo singularity build swist Singularity.swist
singularity/swist_fmri_image> . /opt/conda/bin/activate neuro
(neuro) Singularity swist:~/swist-> python
Python 3.6.5 | packaged by conda-forge | (default, Apr 6 2018, 13:39:56)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import seaborn
>>> import bids
>>>
Run Code Online (Sandbox Code Playgroud)
我已经把这件事的全部记录概括为要点
这里有一些有用的调试技巧!我解决上述问题的方法是进行构建,用 conda 注释掉触发错误的最后几行。然后我可以构建一个可写沙箱:
sudo singularity build --sandbox swist-box Singularity.swist
Run Code Online (Sandbox Code Playgroud)
并以可写方式写入外壳。这将允许我进行更改和测试。
sudo singularity shell --writable swist-box
$ whoami
root
Run Code Online (Sandbox Code Playgroud)
由于容器具有可写性,这意味着更改将持续存在,因此您可以退出 root 身份,然后在用户空间中进行编辑以测试您的 root 更改是否确实解决了问题!
singularity shell swist-box
$ whoami
neuro
Run Code Online (Sandbox Code Playgroud)
然后,当您认为一切正常时,删除映像并从头开始构建并进行测试。
rm -rf swist-box swist
sudo singularity build swist Singularity.swist
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
699 次 |
| 最近记录: |