I can't install TensorFlow-macos and TensorFlow-metal

Dear All,

I am a Data Scientist and waiting for GPU accelerating for years, and I am thrilled while Apple announced it will come at MacOS 12.

linkText

And so, I updated my OS to Monterey Beta and tried to install TensorFlow-Metal a few days ago. However, all installing instruction commands not work at all.

After that, I looked into pypi.org and found out there are whl files for TensorFlow-macos and TensorFlow-metal. So, I tried to pip install both whl files. Yet, noting work again.

Here is the screenshot for installing.

I would very much appreciate if you can help me to solve this issue.

Sincerely,

Answered by tngchi in 680144022

I was able to install tensorflow-macos and tensrflow-metal on intel based iMac

$ python3 -m venv tensorflow-metal-test
$ source tensorflow-metal-test/bin/activate
$ cd tensorflow-metal-test/
$ python -m pip install -U pip
$ pip install tensorflow-macos
$ pip install tensorflow-metal

and my version

$ python -V
Python 3.8.2
$ pip -V
pip 21.1.2 from /Us...
$ pip list
Package                 Version
----------------------- -------------------
absl-py                 0.13.0
astunparse              1.6.3
cachetools              4.2.2
certifi                 2021.5.30
chardet                 4.0.0
flatbuffers             1.12
gast                    0.4.0
google-auth             1.32.0
google-auth-oauthlib    0.4.4
google-pasta            0.2.0
grpcio                  1.34.1
h5py                    3.1.0
idna                    2.10
keras-nightly           2.5.0.dev2021032900
Keras-Preprocessing     1.1.2
Markdown                3.3.4
numpy                   1.19.5
oauthlib                3.1.1
opt-einsum              3.3.0
pip                     21.1.2
protobuf                3.17.3
pyasn1                  0.4.8
pyasn1-modules          0.2.8
requests                2.25.1
requests-oauthlib       1.3.0
rsa                     4.7.2
setuptools              41.2.0
six                     1.15.0
tensorboard             2.5.0
tensorboard-data-server 0.6.1
tensorboard-plugin-wit  1.8.0
tensorflow-estimator    2.5.0
tensorflow-macos        2.5.0
tensorflow-metal        0.1.1
termcolor               1.1.0
typing-extensions       3.7.4.3
urllib3                 1.26.6
Werkzeug                2.0.1
wheel                   0.36.2
wrapt                   1.12.1

Have you checked to ensure you are using Python 3 instead of Python 2? Typically, you use the python3 command to ensure you are using version 3. You can run python --version to see which version you are using. I see you have a virtual environment above, so maybe it is 3.

I also wanted to mention that the wheel you have downloaded is for x86_64.

I was able to install Tensorflow 2.5 on an Intel based iMac using the following sequence of commands in Terminal:

python3 -m pip install virtualenv
python3 -m virtualenv macml
source macml/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install tensorflow-macos
python3 -m pip install tensorflow-metal

Maybe you could try that and see if you get different results rather than installing from the downloaded wheel?

Sorry for the bad typesetting in the comment, here is the screenshot for installing information

Accepted Answer

I was able to install tensorflow-macos and tensrflow-metal on intel based iMac

$ python3 -m venv tensorflow-metal-test
$ source tensorflow-metal-test/bin/activate
$ cd tensorflow-metal-test/
$ python -m pip install -U pip
$ pip install tensorflow-macos
$ pip install tensorflow-metal

and my version

$ python -V
Python 3.8.2
$ pip -V
pip 21.1.2 from /Us...
$ pip list
Package                 Version
----------------------- -------------------
absl-py                 0.13.0
astunparse              1.6.3
cachetools              4.2.2
certifi                 2021.5.30
chardet                 4.0.0
flatbuffers             1.12
gast                    0.4.0
google-auth             1.32.0
google-auth-oauthlib    0.4.4
google-pasta            0.2.0
grpcio                  1.34.1
h5py                    3.1.0
idna                    2.10
keras-nightly           2.5.0.dev2021032900
Keras-Preprocessing     1.1.2
Markdown                3.3.4
numpy                   1.19.5
oauthlib                3.1.1
opt-einsum              3.3.0
pip                     21.1.2
protobuf                3.17.3
pyasn1                  0.4.8
pyasn1-modules          0.2.8
requests                2.25.1
requests-oauthlib       1.3.0
rsa                     4.7.2
setuptools              41.2.0
six                     1.15.0
tensorboard             2.5.0
tensorboard-data-server 0.6.1
tensorboard-plugin-wit  1.8.0
tensorflow-estimator    2.5.0
tensorflow-macos        2.5.0
tensorflow-metal        0.1.1
termcolor               1.1.0
typing-extensions       3.7.4.3
urllib3                 1.26.6
Werkzeug                2.0.1
wheel                   0.36.2
wrapt                   1.12.1

I got this error with (tensorflow-metal) virtualenv on Big Sur with an AMD Radeon 5700 XT GPU

tensorflow-metal/lib/python3.8/site-packages/tensorflow-plugins/libmetal_plugin.dylib, 6): Symbol not found: _TF_AssignUpdateVariable

  Referenced from: /Users/davidlaxer/tensorflow-metal/lib/python3.8/site-packages/tensorflow-plugins/libmetal_plugin.dylib

  Expected in: flat namespace

$ nm /Users/davidlaxer/tensorflow-metal/lib/python3.8/site-packages/tensorflow-plugins/libmetal_plugin.dylib | grep _TF_AssignUpdateVariable

                 U _TF_AssignUpdateVariable

I have installed python 3.8.10 via pyenv and with the following comnand I am able to install both tensorflow-macos and tensorflow-metal without the complaint of distribution mismatch

GRPC_PYTHON_BUILD_SYSTEM_ZLIB=true pip install tensorflow-macos
GRPC_PYTHON_BUILD_SYSTEM_ZLIB=true pip install tensorflow-metal

I had the same issue. It seems that the error is from Python 3.8 in Anaconda. (Virtualenv, the recommended approach, seems fine).

The following command should be able to by pass the error:

SYSTEM_VERSION_COMPAT=0 pip install tensorflow-macos tensorflow-metal
15

I am unable to install tensor flow on my MacBook Air M1. the kernel dies as soon as I import tensorflow . can anyone help me with it?

Same issue, pip install tensorflow-macos worked upgrading pip pip install --upgrade pip.

pip install tensorflow-macos , is failing with below error

ERROR: Cannot install tensorflow-macos==2.5.0 and tensorflow-macos==2.6.0 because these package versions have conflicting dependencies.

All of my excitement of having M1 is gone..having hard time to install tensor flow

 ERROR: Command errored out with exit status 1:   command: /Users/tensorflow-metal-test/bin/python /private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-standalone-pip-j863mk96/env_pip.zip/pip install --ignore-installed --no-user --prefix /private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-build-env-xlyfg9ik/normal --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'numpy==1.14.5; python_version == "3.7"' 'Cython>=0.29; python_version < "3.8"' 'numpy==1.19.3; python_version >= "3.9"' 'numpy==1.12; python_version == "3.6"' 'numpy==1.17.5; python_version == "3.8"' 'Cython>=0.29.14; python_version >= "3.8"' pkgconfig     cwd: None  Complete output (4475 lines):  Ignoring numpy: markers 'python_version == "3.7"' don't match your environment  Ignoring Cython: markers 'python_version < "3.8"' don't match your environment  Ignoring numpy: markers 'python_version >= "3.9"' don't match your environment  Ignoring numpy: markers 'python_version == "3.6"' don't match your environment  Collecting numpy==1.17.5   Using cached numpy-1.17.5.zip (6.4 MB)   Preparing metadata (setup.py): started   Preparing metadata (setup.py): finished with status 'done'  Collecting Cython>=0.29.14   Using cached Cython-0.29.24-py2.py3-none-any.whl (979 kB)  Collecting pkgconfig   Using cached pkgconfig-1.5.5-py3-none-any.whl (6.7 kB)  Using legacy 'setup.py install' for numpy, since package 'wheel' is not installed.  Installing collected packages: pkgconfig, numpy, Cython    Running setup.py install for numpy: started    Running setup.py install for numpy: finished with status 'error'    ERROR: Command errored out with exit status 1:     command: /Users/tensorflow-metal-test/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-install-jvvwjkem/numpy_084dfcc1797443919f4762bdae8cfe0e/setup.py'"'"'; file='"'"'/private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-install-jvvwjkem/numpy_084dfcc1797443919f4762bdae8cfe0e/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-record-1k3_j4wg/install-record.txt --single-version-externally-managed --prefix /private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-build-env-xlyfg9ik/normal --compile --install-headers /private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-build-env-xlyfg9ik/normal/include/site/python3.8/numpy       cwd: /private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-install-jvvwjkem/numpy_084dfcc1797443919f4762bdae8cfe0e/    Complete output (4453 lines):    Running from numpy source directory.       Note: if you need reliable uninstall behavior, then install    with pip instead of using setup.py install:        - pip install .    (from a git repo or downloaded source                  release)     - pip install numpy  (last NumPy release on PyPi)

error: Command "clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -DNPY_INTERNAL_BUILD=1 -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNO_ATLAS_INFO=3 -DHAVE_CBLAS -Ibuild/src.macosx-10.14-arm64-3.8/numpy/core/src/umath -Ibuild/src.macosx-10.14-arm64-3.8/numpy/core/src/npymath -Ibuild/src.macosx-10.14-arm64-3.8/numpy/core/src/common -Inumpy/core/include -Ibuild/src.macosx-10.14-arm64-3.8/numpy/core/include/numpy -Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/Users/tensorflow-metal-test/include -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -Ibuild/src.macosx-10.14-arm64-3.8/numpy/core/src/common -Ibuild/src.macosx-10.14-arm64-3.8/numpy/core/src/npymath -Ibuild/src.macosx-10.14-arm64-3.8/numpy/core/src/common -Ibuild/src.macosx-10.14-arm64-3.8/numpy/core/src/npymath -c numpy/core/src/multiarray/alloc.c -o build/temp.macosx-10.14-arm64-3.8/numpy/core/src/multiarray/alloc.o -MMD -MF build/temp.macosx-10.14-arm64-3.8/numpy/core/src/multiarray/alloc.o.d -faltivec -I/System/Library/Frameworks/vecLib.framework/Headers" failed with exit status 1    ----------------------------------------  ERROR: Command errored out with exit status 1: /Users/tensorflow-metal-test/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-install-jvvwjkem/numpy_084dfcc1797443919f4762bdae8cfe0e/setup.py'"'"'; file='"'"'/private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-install-jvvwjkem/numpy_084dfcc1797443919f4762bdae8cfe0e/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-record-1k3_j4wg/install-record.txt --single-version-externally-managed --prefix /private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-build-env-xlyfg9ik/normal --compile --install-headers /private/var/folders/8s/t8kzlftn5x5c2mw37dd7lbs00000gn/T/pip-build-env-xlyfg9ik/normal/include/site/python3.8/numpy Check the logs for full command output.

Sandeep, I had similar problems, trying to install tensorflow-macos via pyenv and "pyenv virtualenv", it simply didn't go anywhere. What finally did the trick for me was following the instructions at https://developer.apple.com/metal/tensorflow-plugin/

This involves installing "Conda", using it to install the dependencies and finally installing tensorflow-macos and tensorflow-metal via "python -m pip install ...".

This got me up and running on my MacBook Pro M1/max. Good luck.

So, tensorflow-macos & tensorflow-metal is now only available on ARM64 platform? I tried conda and pip and all get "No matching distribution found for ..." ERROR. BTW I'm under 12.1 Beta

It just can't find the appropriate distribution and the following is what I got if I install it with the "SYSTEM_VERSION_COMPAT=0" prefix then run the tutorial on the https://www.tensorflow.org/tutorials/quickstart/beginner

【-: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.】

【-: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.】

【-: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)】

【Epoch 1/5】

【-: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:112] Plugin optimizer for device_type GPU is enabled.】

【- python[1824:41366] -[MPSGraph adamUpdateWithLearningRateTensor:beta1Tensor:beta2Tensor:epsilonTensor:beta1PowerTensor:beta2PowerTensor:valuesTensor:momentumTensor:velocityTensor:gradientTensor:name:]: unrecognized selector sent to instance 0x60000fe67480】

If this helps any, there might be a Metal port to Swift for TensorFlow in a few months. It would work without any prior configuration because you would just need to add a Swift package dependency to an Xcode project.

hey hawkiyc, if you resolve the issue, please share with me how. cuz i am facing that issue rn.

I'll add that like others, python 3.8.X is required.

Then run:

SYSTEM_VERSION_COMPAT=0 python -m pip install tensorflow-macos (this will give you tensorflow-macos version 2.7 - don't get excited yet)

SYSTEM_VERSION_COMPAT=0 python -m pip install tensorflow-metal (this will also succeed)

Install your other stuff as normal with conda (pandas, scikit-learn, jupyterlab, etc)

Then run your code. You can run:

print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))

Num GPUs Available: 1

So far so good right?!?! Looking Good!

Now run your model...

First line:

Metal device set to: AMD Radeon Pro 5600M keeps looking better and better !!!

and then the kernel dies...

2022-01-13 17:02:36.447465: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2022-01-13 17:02:36.448221: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support. 2022-01-13 17:02:36.448581: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)

Will tensorflow-macos ever work for Intel ?

In my case I am using Miniconda.

I also encountered encountered the above problem. But when I installed python 3.8 in a new environment (So that my other dependencies are not affected), I was able to solve the issue.(Mine is M1 Pro chip, May also work for M1 and M1 max)

conda create --name tensor-env  python = 3.8      #creating new environment named "tensor-env" with python version 3.8
conda activate tensor-env

# All the below 3 installation is necessary to make use of M1's GPU  

conda install -c apple tensorflow-deps
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal

And if all the above installations are successful, then you can use Tensorflow which is designed to be used in Apple M1 GPU.

Hi all, I am using Monterey, version 12.3.1, M1 chip. The following procedures work for me on Python 3.9.12.

  1. create virtual environment and active it.

 python3 -m venv test_env

 source test_env/bin/activate

  1. use brew to install hdf5 first and export the path

 brew install hdf5

 export HDF5_DIR=/opt/homebrew/Cellar/hdf5/1.12.2

  1. install packages via pip3

 pip3 install --no-binary=h5py h5py

 pip3 install tensorflow-macos

 pip3 install tensorflow-metal

Hope it will help you. :)

TensorFlow for M1 till support up to python 3.8 [as per 16th Feb 2023]

  1. install conda [miniconda]
  2. create virtual env with conda for python version 3.8
  3. activate into that virtual env
  4. now run commands to install tensorflow and related lib

Thanks

I'm having same issue on m1 mac using python 3.10.10 and pip 23.0.1. According to google docs python up to 3.11 should work.

Just a head up - wIth M3 Max I'm not see ing Meta with Python 3.12.3 (Sonoma 14.4.1)

python -m pip install tensorflow-metal ERROR: Could not find a version that satisfies the requirement tensorflow-metal (from versions: none) ERROR: No matching distribution found for tensorflow-metal

I was not able to get tf to work with the latest versions. Using anaconda (via brew) I was finally able to get this to work by using slightly older versions:

 conda install python=3.11
 pip install tensorflow==2.15.1
 pip install tensorflow-metal

then:

import tensorflow as tf
print(tf.__version__)
print(tf.config.list_physical_devices('GPU'))

gave me:

2.15.1
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

I can't install TensorFlow-macos and TensorFlow-metal
 
 
Q