Conda init problems

Hi,
I was trying to create a custom conda environment. (I was hoping to install packages that don’t seem to be compatible with conda/analysis3.) If I try to run conda init I get the same kind of errors that @mmr0 got in her post:

Since that topic was closed, I’m starting a new one here.

To be clear, I’m not seeking to use the conda/analysis here, I am purely trying to run conda init in order to create a custom conda environment. Please help.

I hope somebody comes along to give a better answer here in a bit, but I’ve had that CondaError: Run 'conda init' before 'conda activate' problem on my local machine, and you can just get around it by activating conda manually

> source /path/to/conda/bin/activate
> conda activate <my_env_name>

Does that work in this instance?

Thanks Jemma. I tried your suggestion but I got this message:

source /g/data/xp65/public/apps/med_conda_scripts/analysis3-25.07.d/bin/activate
realpath: invalid option -- '/'
Try 'realpath --help' for more information.
bash: /launcher_conf.sh: No such file or directory
FATAL:   configuration disallows users from running sandbox containers

Thanks to @jemmajeffree we have a workaround for getting past the conda init problem.
If I run:

source /g/data/xp65/public/apps/med_conda/etc/profile.d/conda.sh

Then this effectively gets past the conda initstage, and after that I can activate my custom environment:

conda activate /g/data/y99/dkh157/tmm_2025/pypet

This will do for now… still feel like there must be a cleaner way to run conda init. Anyway, thanks @jemmajeffree

1 Like

Hi @dkhutch,

On Gadi is preferrable not to run conda init, but rather use an already available conda/micromamba executable and setup (similar to what the conda init command would do). Then add a ~/.condarc file for its configuration.

I would strongly suggest switching to micromamba, which is much faster and has pretty much all the conda functionalities a general user would need.

My suggestion (and my setup on Gadi) is the following:

Micromamba executable

In my ~/.bash_profile I have the following lines:

# >>> mamba initialize >>>
export MAMBA_EXE='/g/data/vk83/apps/base_conda/bin/micromamba';
echo "Initializing 'micromamba' using $MAMBA_EXE"
export MAMBA_ROOT_PREFIX='/scratch/$PROJECT/$USER/micromamba';
__mamba_setup="$($MAMBA_EXE shell hook --shell bash --root-prefix $MAMBA_ROOT_PREFIX 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__mamba_setup"
else
    alias micromamba="$MAMBA_EXE"  # Fallback on help from mamba activate
fi
unset __mamba_setup
# <<< mamba initialize <<<

This runs the setup for mircomamba, setting its exe to /g/data/vk83/apps/base_conda/bin/micromamba and its root prefix to /scratch/$PROJECT/$USER/micromamba.

Configuration

micromamba can be configured with a ~/.condarc file.
I suggest something similar to:

auto_activate_base: false
envs_dirs:
  - $MAMBA_ROOT_PREFIX/envs
pkgs_dirs:
  - $MAMBA_ROOT_PREFIX/pkgs
conda-build:
  root-dir: $MAMBA_ROOT_PREFIX/bld
channels:
  - accessnri
  - conda-forge
  - nodefaults
changeps1: true

Micromamba alias (optional)

If you want to alias micromamba with something different or shorter, you can add an alias in your ~/.bashrc file. For example, I have it aliased to mamba:

alias mamba='micromamba'

Conda

A very similar approach could be done with conda if needed. The only reason to also need conda I think is being able to build conda packages using conda build.
In this case, the following can be added to the ~/.bash_profile after the micromamba setup above:

# >>> conda initialize >>>
export CONDA_EXE=/g/data/xp65/public/apps/med_conda/bin/conda
echo "Initializing 'conda' using $CONDA_EXE"
__conda_setup="$($CONDA_EXE shell.bash hook --root-prefix $MAMBA_ROOT_PREFIX 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "$CONDA_EXE" ]; then
        . "$(dirname $(dirname $CONDA_EXE))/etc/profile.d/conda.sh"
    else
        export PATH="$(dirname $CONDA_EXE):$PATH"
    fi
fi
# <<< conda initialize <<<

In this case, I would keep the same ~/.condarc configuration and make sure to only use conda to build packages, and micromamba for all the rest.

2 Likes

Huh, thanks

Are there docs/tutorials on this somewhere? (and if so, where? If not, would such a thing be possible?) I didn’t realise it existed.

Otherwise I’ll bookmark this post for future reference.

There were some tutorials in the “old” CLEX CMS wiki, but most of the content is outdated, so I would say the updated tutorial is the one I wrote above :smile:

1 Like

Thanks for the info Davide! That’s handy to have.