Search code examples
pythoncondazshapple-m1

How can I create a script to switch between my ARM conda and x86 conda?


I am on an apple silicon M1 MacBook Pro. I would like to have a native ARM python environment, and an environment that runs on x86 architecture with rosetta 2. I have installed two mini forge distributions, both in the home directory: miniforge3 for the native ARM installation and miniforge3_x86_64 for the x86 installation.


Solution

  • So far, the best solution I've found is to start the terminal with Rosetta 2, then run a function I have saved in .zshrc to initialize the correct conda installation so that I can use the correct architecture for my needs depending on the situation.

    My current solution is the following function named x86:

    x86 () {
    
    conda deactivate
    
    # >>> conda initialize >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$('/Users/$USERNAME/miniforge3_x86_64/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
    if [ $? -eq 0 ]; then
        eval "$__conda_setup"
    else
        if [ -f "/Users/$USERNAME/miniforge3_x86_64/etc/profile.d/conda.sh" ]; then
            . "/Users/$USERNAME/miniforge3_x86_64/etc/profile.d/conda.sh"
        else
            export PATH="/Users/$USERNAME/miniforge3_x86_64/bin:$PATH"
        fi
    fi
    unset __conda_setup
    # <<< conda initialize <<<
    
    export PATH="/Users/$USERNAME/miniforge3_x86_64/bin:$PATH" 
    export PATH="/Users/$USERNAME/miniforge3_x86_64/condabin:$PATH"
    }
    

    I am still feeling this out. I may add some aliases within the function as well so things like pip do not conflict, but I hope that by prepending the x86 paths the correct packages will be referenced