title: Activating a conda environment in a singularity recipe
body: <p>I'm new to singularity and I would like to activate a conda environment (<code>myenv</code>) within a singularity recipe in order to install a package into it (<code>mypkg</code>). I've read some related posts but the answers did not solve my problem although the questions are very similar (<a href="https://stackoverflow.com/q/56446195/3894837">Activate conda environment on execution of Singularity container in Nextflow</a>, <a href="https://stackoverflow.com/q/55168018/3894837">How to activate an Anaconda environment in a Singularity recipe</a>, <a href="https://stackoverflow.com/q/50259231/3894837">Building Singularity recipe from Nipype docker image CommandNotFound</a>). Could you help me to find what I've missed please?</p>
  
  <p>In my case, <code>myenv</code> is automatically activated when I execute the container but I don't succeed to activate it during the container building for installing <code>mypkg</code>. I don't have any error message but the package is installed in the base env instead of <code>myenv</code>.</p>
  
  <pre><code>Bootstrap: docker
  From: ubuntu:18.04
  
  %files
      myenv.yml
  
  %environment
      export LC_ALL=C
      export LC_NUMERIC=en_GB.UTF-8
      export PATH="/opt/miniconda/bin:$PATH"
      export PATH="/opt/miniconda/envs/$(head -1 myenv.yml | cut -d' ' -f2)/bin:$PATH"
  
  %runscript
      exec "$@"
  
  %post
      # miniconda2: get miniconda2 version 4.5.1
      wget https://repo.continuum.io/miniconda/Miniconda2-4.7.12.1-Linux-x86_64.sh -O miniconda.sh
  
      #install conda
      bash miniconda.sh -b -p /opt/miniconda
      export PATH="/opt/miniconda/bin:$PATH"
  
      #install conda env.yml file
      echo ". /opt/miniconda/etc/profile.d/conda.sh" &gt;&gt; $SINGULARITY_ENVIRONMENT
      echo "conda activate $(head -1 myenv.yml | cut -d' ' -f2)" &gt;&gt; $SINGULARITY_ENVIRONMENT
      /opt/miniconda/bin/conda env create -f myenv.yml
  
      # Activate conda env, clone and install mypkg
      . /opt/miniconda/bin/activate myenv &amp;&amp;
      git clone https://github.com/mypkg.git &amp;&amp;
      cd mypkg&amp;&amp;
      python setup.py install
  
  </code></pre>