Skip to content

Activating environment inside container. #45

@sorenwacker

Description

@sorenwacker

I have problems activating the environment by default within a container.
Is micromamba using a different installation directory than conda?

Apptainer.def

Bootstrap: docker
From: mambaorg/micromamba:1.5.8

%files
    environment.yaml /environment.yaml
    requirements.txt /requirements.txt

%post
    apt-get update && apt-get install -y libopenmpi-dev curl wget vim watch procps ncdu tree

    micromamba create -n __apptainer__ && \
    micromamba install -n __apptainer__ --file environment.yaml && \
    micromamba clean --all --yes

    # Update PATH to include micromamba binaries and other environment variables
    echo 'export PATH="/usr/bin/micromamba:$PATH"' >> $SINGULARITY_ENVIRONMENT

    # Add micromamba shell hook and activation to Singularity environment script
    echo 'micromamba shell init --shell bash' >> $SINGULARITY_ENVIRONMENT

    # Add micromamba shell hook and activation to Singularity environment script
    echo '/usr/bin/micromamba activate __apptainer__' >> $SINGULARITY_ENVIRONMENT

Apptainer command

# Run script
srun apptainer exec \
    --nv \
    --env-file ~/.env \
    -B /home/:/home/ \
    $APPTAINER_SIF \
    python script.py

Error

source: open /opt/conda/bin/activate: no such file or directory
critical libmamba Shell not initialized

Output

'micromamba' is running as a subprocess and can't modify the parent shell.
Thus you must initialize your shell before using activate and deactivate.

To initialize the current  shell, run:
    $ eval "$(micromamba shell hook --shell )"
and then activate or deactivate with:
    $ micromamba activate
To automatically initialize all future () shells, run:
    $ micromamba shell init --shell  --root-prefix=~/micromamba
If your shell was already initialized, reinitialize your shell with:
    $ micromamba shell reinit --shell 
Otherwise, this may be an issue. In the meantime you can run commands. See:
    $ micromamba run --help

Supported shells are {bash, zsh, csh, xonsh, cmd.exe, powershell, fish}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions