this introduction is based on:
https://betterdatascience.com/install-tensorflow-2-7-on-macbook-pro-m1-pro/
I’ll show you how to install TensorFlow 2.7 on MacBook Pro M1 Pro. Everything you’ll see will work on regular M1 and M1 Max chips, as long as it’s Apple Silicon. We’ll also verify TensorFlow was installed by training a simple neural network.
Prerequisites
You’ll need a couple of things installed before you can even think about TensorFlow – Homebrew, XCode tools, and Honda. You can install the first two through Mac’s terminal with the following commands:
Change shell from default zsh to bash by execute the following command:
chsh -s /bin/bash
if you are interested in all available Shells execute the following command:
cat /etc/shells
to install homebrew for package management execute the above command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
for install the Xcode Command Line Tools execute:
xcode-select --install
install my perferred IDE VSCodium (Free/Libre Open Source Software Binaries of VS Code)for development in python:
brew install --cask vscodium
Finally, you'll need Anaconda. As of now, Miniforge runs natively on all M1 chips (M1, M1 Pro, M1 Max), so we'll stick with it. Download the ARM64 version for Mac - the one marked on the image below:
Finally, you’ll need Anaconda. As of now, Miniforge runs natively on all M1 chips (M1, M1 Pro, M1 Max), so we’ll stick with it. Download the ARM64 version for Mac – the one marked on the image below:

It will download an SH file. You’ll have to change its permissions and run it through the terminal:
cd <path_to_the_downloaded_file>
chmod -x Miniforge3-MacOSX-arm64.sh
./Miniforge3-MacOSX-arm64.sh

As the instructions suggest – press Enter to continue. Stick with the default options, and in a minute or so you should have Miniforge installed!
Now create a new virtual environment based on Python 3.9. I’ve named mine tf_env
:
conda create --name tf_env python=3.9
The new environment will be created after a couple of seconds, activate the environment:
conda activate tf_env
Install TensorFlow and TensorFlowe Metal on the M1 Pro Chip
The process of installing TensorFlow with GPU support has become a lot smoother over the last couple of months. Since the macOS Monterey release, I’d be amazed if anyone runs into any trouble by following these instructions.
We’ll start by installing TensorFlow dependencies from Apple:
conda install -c apple tensorflow-deps -y
Once installed, use the following command to install TensorFlow on M1 Pro Macbook:
python -m pip install tensorflow-macos
The installation will take a couple of minutes, as Miniforge has to pull a ton of fairly large packages. The last step is to install the GPU support for TensorFlow on M1 Pro Macbooks with the Metal plugin:
pip install tensorflow-metal
And that’s all – you now have TensorFlow and all of its dependencies installed. I’ll also install JupyterLab, just so we can easily build and train a simple neural network:
conda install -c conda-forge jupyter jupyterlab -y
Once installed, launch a new Jupyter session:
jupyter lab
I’ll see you in the next section where we’ll train a simple neural network with TensorFlow on the M1 Pro chip.
Train a Neural Network With TensorFlow on MacBook Pro M1 Pro
You should have a JupyterLab session started, or any other code editor opened before proceeding. Use the following code snippet to import TensorFlow and verify it was installed:
import tensorflow as tf
tf.__version__
Also, print the list of available training devices – just to verify TensorFlow on M1 Pro Macbook sees the GPU:
tf.config.list_physical_devices()
Here are the outputs for both:

And there you have it – TensorFlow on the M1 Pro chip was installed successfully, and it also sees both CPU and GPU as available training devices!
Neueste Kommentare