• 将conda虚拟环境打包并集成到singularity镜像中


    1. 使用yml文件打包

    conda activate your_env
    conda env export > environment.yml
    
    • 1
    • 2

    编写cond.def文件

    Bootstrap: docker
    
    From: continuumio/miniconda3
    
    %files
        environment.yml
    
    %post
        /opt/conda/bin/conda env create -f environment.yml
    
    %runscript
        exec /opt/conda/envs/$(head -n 1 environment.yml | cut -f 2 -d ' ')/bin/"$@" 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    生成镜像:

    singularity build conda.sif conda.def
    
    • 1

    2. 利用tar包

    2.1 安装conda-pack

    pip install conda-pack
    
    • 1

    版本需要0.7以上。

    2.2 导出tar包

    conda-pack -n <MY_ENV> -o packed_environment.tar.gz
    
    • 1

    编写conda.def文件:

    Bootstrap: docker
    
    From: continuumio/miniconda3
    
    %files
        packed_environment.tar.gz /packed_environment.tar.gz
    
    %post
        tar xvzf /packed_environment.tar.gz -C /opt/conda
        conda-unpack
        rm /packed_environment.tar.gz
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    生成镜像:

    singularity build --fakeroot <OUTPUT_CONTAINER.sif> conda.def
    
    • 1

    3. 在已有基础上构建

    def:

    Bootstrap: localimage
    From: local_image.sif
    
    %environment
        # set up environment for when using the container
        . /opt/conda/etc/profile.d/conda.sh
        conda activate
    
    %post
        apt-get update -y
        apt-get install -y \
                build-essential \
    		    wget \
                cmake \
                g++ \
                r-base-dev \
    			make
    	    
    
        R -e "install.packages('cowsay', dependencies=TRUE, repos='http://cran.rstudio.com/')"
    	
        # install miniconda
        wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
        bash Miniconda3-latest-Linux-x86_64.sh -b -f -p /opt/conda
        rm Miniconda3-latest-Linux-x86_64.sh
    
        # install conda components - add the packages you need here
        . /opt/conda/etc/profile.d/conda.sh
        conda activate
        conda install -y -c conda-forge numpy cowpy
        conda update --all
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    4. 沙盒模式

    4.1 构建沙河目录

    singularity build --sandbox lolcow/ library://sylabs-jms/testing/lolcow
    
    • 1

    4.2 进入沙盒

    singularity shell --writable lolcow/
    
    • 1

    4.3 将沙盒打包成sif

    singularity build lolcow.sif lolcow/
    
    • 1

    5. 设置环境变量

    pytorchcmake未设置cuda环境变量

    SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "path\\boost_1_80_0")
    SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "path\\boost_1_80_0\\libs")
    
    • 1
    • 2

    可以通过如下设置:

    %environment
        export CUDA_INCLUDE_DIRS=/opt/conda/cuda/include
        export CUDA_CUDART_LIBRARY=/opt/conda/cuda/lib
    
        export LIBRARY_PATH=/opt/conda/cuda/lib:$LIBRARY_PATH
        export CPATH=/opt/conda/cuda/include:$CPATH
        export PATH=/opt/conda/cuda:$PATH
    %post
       mkdir -p /opt/conda/cuda
       conda install cuda -c nvidia -p /opt/conda/cuda
       
       mkdir -p /opt/conda/cudnn
       conda install -c anaconda cudnn -p /opt/conda/cudnn
    
       export PATH=/opt/conda/cuda:$PATH
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    pytorchcmake未设置cudnn环境变量,通过如下方法设置:

    export CUDNN_ROOT=/path/to/cudnn
    
    • 1
  • 相关阅读:
    #paypay付款测试#
    华为孟晚舟:从最惨千金 到最强战士
    [免费专栏] Android安全之Linux+Windows安装r2Frida环境配置及使用
    MSDC 4.3 接口规范(1)
    【深入浅出 Yarn 架构与实现】3-3 Yarn Application Master 编写
    腾讯云轻量应用服务器使用场景列举说明
    OpenCV的石头检测~
    [springmvc学习]8、JSR 303验证及其国际化
    二叉搜索树
    这样讲Redis 主从复制的工作原理,或许你真的能听懂~
  • 原文地址:https://blog.csdn.net/u012897374/article/details/133664567