Installing tensorflow on M1 with pyenv
Tensorflow is tricky to install on an M1 mac. Here's how I got it working
Install Miniforge with pyenv
pyenv install --list
to get latest version of miniforge. Mine was:
pyenv install miniforge3-4.10.3-10
Activate miniforge env
pyenv activate miniforge3-4.10.3-10
EDIT 23/06/22 — Apparently pyenv no longer uses pyenv activate
so instead use pyenv shell miniforge3-4.10.3-10
– Thanks David Lasry. You could also use set the miniforge version to your local directory using pyenv local [version]
Create a conda env
conda create --name env_tensorflow python=3.9
Activate env:
conda activate env_tensorflow
You are now in a conda env in a pyenv env. Envception.
Install tensorflow dependencies
conda install -c apple tensorflow-deps
Install tensorflow-macos
You'll have to use pip for this.
pip install tensorflow-macos
ignore any errors.
To use GPU install tensorflow-metal
pip install tensorflow-metal
Try and import tensorflow in the python shell
python
>>> import tensorflow as tf
If it works it works!