Setting upTensorFlow on Your M1/M2 Apple Silicon MacBooks

TensorFlow, an extremely popular library for machine learning and AI

What you need:

  1. Conda (Anaconda & Miniconda both suffice, see this post on which one better suits you)
  2. Terminal

Step 1

Open Terminal and create a directory for the virtual environment

mkdir tensorflow_venv
cd tensorflow_venv

Step 2

Activate a Conda environment with a Python version compatible with TensorFlow (I was prompted that TensorFlow does not support Python 3.8, so I created a Python 3.7 environment instead)

conda create --prefix ./env python=3.7
conda activate ./env

Step 3

Now that python is installed successfully into this environment, use Conda to install TensorFlow

conda install tensorflow
Downloading and Extracting Packages
......
Preparing transaction: done
Verifying transaction: doneExecuting transaction: doneRetrieving notices: ...working... done

Step 4 (Setting up in PyCharm)

Open a project in which you want to set up TensorFlow. Go to Preferences >> Project: Your Project >> Python Interpreter.

Step 5

Click on the “+” sign on the top left to add a new Python interpreter. Under “Base Interpreter”, select: /Users/YourName/tensorflow_venv/env/bin/python[some_version] Checkmark “Inherit global site-packages”, and click “Ok”.

import tensorflow as tf
print(tf.__version__)

if __name__ == '__main__':
pass

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store