Anaconda and MiniConda with Singularity Container


This might be a silly question but I’m curious about the difference of miniconda and anaconda environments inside singularity containers. I currently have miniconda installed and have a couple of environments with it. When i shell into my singularity container with:
singularity shell --writable-tmpfs blahblah.sif

and create a miniconda environment (conda create --name …), it is fine. Unfortunately when I try to activate the environment immediately afterwards, I am getting:

CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’.
To initialize your shell, run

$ conda init <SHELL_NAME>

When I run conda init bash and do it all over again, I am getting the same error. Does anybody know what may be the problem? Thank you.

Singularity can be tricky. When you enter a singularity container, you do not bring anything from your personal environment with it, including your bash_profile/bashrc which anaconda writes to in order to “activate” the terminal.

I am curious why you want to create a conda environment inside a singularity. Typically, singularity is used because you want to use a specific python environment as it is installed in a container. If you let me know what you are ultimately trying to do, maybe I can help.


I would suggest looking at Neurodocker for creating Singularity images. It deals with these sorts of details and lets you mostly focus on what you want in your container.

1 Like

Thank you so much Steven for the nice message.

I am relatively new to working with singularity so forgive me. Most of my questions would be straightened out by a TA or or somebody in a neighboring office but covid has made this more of an adventure.

So one thing that should be said is that I am running the container on a school cluster… and it isn’t the cluster that the first set of whole slide images and experiments were run on. The hope is to continually add different organization’s whole slide images. Also, I think there are two slightly different questions. One, why would one want to use an anaconda environment inside a singularity container if the singularity container already has libraries (torch jupyter etc.) installed? And two, why can I create a miniconda environment inside my singularity shell but can’t activate it immediately afterwards?

For the first point, the cluster manager mentioned that his point was to make a container that is independent of the cluster. That would then be my environment which only has one dependency - a way for me to run a container image (docker, singularity, etc) . I would then have the ability to run that container and get work done no matter what goes on the server(s) I run it. If eventually I would need a different version of something, I can just upgrade it on your container… etc…

I am not completely sure how this is different than using ‘exec’ and ‘writable’ to update or install new software though. I know that a couple of the other people in the lab do use conda environments within their singularity container so there must be a reason (probably pertaining to reproducibility and security). Would you know why?

Okay I understand what you’re going for. I would recommend following the other response here and looking at Neurodocker to create your own images.

1 Like