How to install Tensorflow, Keras on Apple M1?

Ibtisam Ur Rahman
2 min readMay 9, 2021
Photo by Jukan Tateisi on Unsplash

Introduction

We are all having problems installing python or its packages in Apple’s new M1 machines. I have put together simple steps that you can follow to successfully install conda environment and Tensorflow.

Table of Content

  • Install miniforge
  • Add conda to path
  • Install tensorflow and other packages

Install miniforge

Download miniforge for apple silicon from the releases section.

After downloading the installer, run the installer in bash,

bash MINIFORGE_FILE_NAME.sh

Add conda to path, For me it was not running with conda init

export PATH="/Users/username/miniforge3/bin:$PATH"

After adding to path, Run following command to active zsh env:

source ~/.zshrc

You can now test it by running conda

Install Tensorflow

Download environment.yml, It will create env and install all dependencies we need to install tensorflow.

After downloading, Run following command to install from environment.yml

conda env create --file=PATH_TO_ENVIRONMENT.YML --name=YOUR_ENV_NAME_HERE

Activate conda environment

conda activate YOUR_ENV_NAME_HERE

Run following command to install tensorflow:

pip install --upgrade --force --no-dependencies <https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl> <https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl>

You can now test it

import tensorflow
print(tensorflow.__version__)

If you get an error about keras, you can install using pip:

pip install keras

If you get an error about h5py , You can downgrade h5py to 2.10.0

pip install 'h5py==2.10.0' --force-reinstall

I was also getting an error something like this:

python clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly

I got it resolved by following commands:

brew install openblas
OPENBLAS="$(brew --prefix openblas)" pip install numpy pandas

Thanks for reading. You can read more about me here, https://ibtisam.dev

References

Instructions to install TensorFlow in a Conda Environment · Issue #153 · apple/tensorflow_macos

--

--

Ibtisam Ur Rahman

Studying Artificial Intelligence and Deep Learning. Previously Software Engineer