How to configure python conda Environments for both arm64
and x86_64
on M1 Apple Silicon
Adding to the answers, it is possible to configure conda
to use both osx-arm64
(arm64) and osx-64
(x86_64) architectures.
I found adding conda config --env --set subdir osx-arm64
changes the option globally which created issues for me. Some of my projects relied on python dependencies that were only supported in either one or the other architecture not both: specifically tensorflow
.
Install Xcode:
xcode-select --install
Install miniforge3
Install miniforge3 by downloading the shell script from here: https://github.com/conda-forge/miniforge. Ensure you select arm64 (Apple Silicon) architecture. You may need to enable execution of the shell script with:
chmod +x Miniforge3-MacOSX-arm64.sh
Then execute is with:
sh Miniforge3-MacOSX-arm64.sh
Add shortcuts to ~/.zshrc
or ~/.bashrc
:
Add the following code to ~/.zshrc
.
The code will add two shortcut functions to create either an osx-64
or osx-arm64
conda environment.
# Create x86 conda environment
create_x86_conda_environment () {
# example usage: create_x86_conda_environment myenv_x86 python=3.9
CONDA_SUBDIR=osx-64 conda create -n $@
conda activate $1
}
# Create ARM conda environment
create_ARM_conda_environment () {
# example usage: create_ARM_conda_environment myenv_x86 python=3.9
CONDA_SUBDIR=osx-arm64 conda create -n $@
conda activate $1
}
Create conda environment
Now to create a python 3.9.13
osx-64
(x86_64) environment with the name env_x86
:
create_x86_conda_environment env_x86 python=3.9.13
Alternatively for osx-arm64
(arm64) environment:
create_ARM_conda_environment env_ARM python3.9.13
Pip install packages
Once activated you can install packages accordingly. In my case I needed an arm64
environment to install tensorflow-macos
.
conda install -c apple tensorflow-deps
pip install tensorflow-macos tensorflow-metal