SimbaNinja
SimbaNinja

Reputation: 43

Install Tensorflow in MacOs M1

I am struggling to install tensorflow on MacOS Monterey 12.5.1 with M1 Chip

pip3 install tensorflow-macos

pip3 install tensorflow-metal

I keep getting this error: ERROR: Could not find a version that satisfies the requirement python (from versions: none)

I tried venv, I tried miniconda, anaconda, still same issue.

How can I install tensorflow in M1 MacOS ?

Upvotes: 2

Views: 3334

Answers (3)

Kapil Parab
Kapil Parab

Reputation: 1

I was having a hard time figuring out how to get Tensorflow to work on the M4 chip but the following seems to be working:

  1. Install Conda
  2. Execute below:
> conda create -n <YOUR_ENV_NAME>
    
> conda activate <YOUR_ENV_NAME>
    
> conda install python==3.10
    
> conda install tensorflow-macos tensorflow-metal

As of writing this, tensorflow-macos = 2.16.2 and tensorflow-metal = 1.1.0 were installed. Also, the default channels were used.

  1. Code to test working:
import tensorflow as tf

cifar = tf.keras.datasets.cifar100

(x_train, y_train), (x_test, y_test) = cifar.load_data()

model = tf.keras.applications.ResNet50(include_top=True, weights=None, input_shape=(32, 32, 3), classes=100,)
                    
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False) 

model.compile(optimizer="adam", loss=loss_fn, metrics=["accuracy"])

model.fit(x_train, y_train, epochs=3, batch_size=64)

Above Tensorflow code sourced from https://developer.apple.com/metal/tensorflow-plugin/.

Upvotes: 0

Gregor von Laszewski
Gregor von Laszewski

Reputation: 492

brew install [email protected]
/opt/homebrew/Cellar/[email protected]/3.8.16/bin/python3.8  -m venv ~/TF
source ~/TF/bin/activate
pip install --upgrade pip
pip install tensorflow-macos

Upvotes: 1

Morteza
Morteza

Reputation: 54

You can follow installation instructions from the apple developer website. With conda first, you need to install tensorflow-deps with:

conda install -c apple tensorflow-deps

then

python -m pip install tensorflow-macOS
python -m pip install tensorflow-metal

This is the procedure recommended by apple, so if you haven't installed "tensorflow-deps", first try that. Also this is suggested for your problem in the same webpage:

Error: “Could not find a version that satisfies the requirement tensorflow-macos (from versions: none).” A TensorFlow installation wheel that matches the current Python environment couldn’t be found by the package manager. Check that the Python version used in the environment is supported (Python 3.8, Python 3.9, Python 3.10).

So try using the mentioned Python versions. Also, here is the long thread of people facing different issues with TensorFlow on mac, which helped me a lot.

Upvotes: 0

Related Questions