How To Install TensorFlow 2.5 on Apple M1

How To Install TensorFlow 2.5 on Apple M1

💡

Data scientists working on M1 laptops - don't fret. You can install TF 2.5 on your machine easily thanks to a cloneable conda environment.

I have purchased an M1 MacBook Pro in April 2021 and I believe it is an extremely valid machine to do basically anything. With the primarily goal in mind to do deep learning and extensive hyperparameter tuning, I brought my shiny laptop in the office an started fiddling right away.

The excitement was pretty much ruined when I ran

pip install tensorflow

and received this error:

grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl is not a supported wheel on this platform.

To my surprise, I searched online and saw that pip install x would often yield build problems and that Anaconda wasn't even supported yet.

This was bad - should have done my homework before purchasing the M1...

The Community Comes To The Rescue

User Chris Trahey (@ctrahey) on Twitter shared a working configuration based on Tensorflow 2.5 that is easy to install and replicate.

The steps are very simple:

  1. Install Miniforge (NOT Anaconda)
  2. With Miniforge installed, run these commands
1. conda create --name tf25 --file ./conda-explicit.txt
2. conda activate tf25
3. pip install --no-deps -r requirements.txt
4. python confirm.py

The output should be

Init Plugin
Init Graph Optimizer
Init Kernel
Running TensorFlow 2.5.0 with 1 GPUs recognized

If you see this, then your environment was correctly installed and you can proceed on doing deep learning on your M1 laptop.

How To Clone Your TF2.5 Environment

To use this configuration on your other projects, simply run

conda create --name name_of_your_new_environment --clone name_of_tf2.5_environment

Then access your new environment and start using it as you would normally.