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,

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

Add a Comment

Accepted Reply

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
  • Thank you very much for your information. This problem resulted from Python 3.9. I succeeded in installing tf-macos and tf-metal in a python 3.8 env.

  • Can you recreate how you were able to get it to work after using a python 3.8 environment? I had the same issue with python 3.9.5, but when I load a python 3.8 environment I still get the same error:

    (tensorflow-metal) ~ % python -V Python 3.8.10 (tensorflow-metal) ~ % pip install tensorflow-macos ERROR: Could not find a version that satisfies the requirement tensorflow-macos (from versions: none) ERROR: No matching distribution found for tensorflow-macos
  • How did you get Python 3.8? I am on Monterey release now and System python3 is 3.7: which python3 -> /usr/bin/python3; python3 --version ->  Python 3.7.3. Installing Python 3.8 from anaconda or python.org both still give me the error in the original post.

Replies

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.

  • Yes, I am running python 3.8.10. And for whl files, I am using MacBook Pro 16' with intel CPU, so, I do have to use the X86_64 version.

Add a Comment

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?

  • Still not work for me, that's so wired.

    Here is what I got, (base) hawkiyc@hawkiyc envs % source tf_metal/bin/activate (tf_metal) (base) hawkiyc@hawkiyc envs % python3 -m pip install --upgrade pip Requirement already satisfied: pip in ./tf_metal/lib/python3.9/site-packages (21.1.2) (tf_metal) (base) hawkiyc@hawkiyc envs % python3 -m pip install tensorflow-macos  ERROR: Could not find a version that satisfies the requirement tensorflow-macos (from versions: none) ERROR: No matching distribution found for tensorflow-macos

    Sincerely,

  • I was able to run all the steps mentioned above but import tensorflow is still not working.

    import tensorflow as tf - works print(tf.version) --- NameError: name 'tf' is not defined

    Could you please help?

Add a Comment

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

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
  • Thank you very much for your information. This problem resulted from Python 3.9. I succeeded in installing tf-macos and tf-metal in a python 3.8 env.

  • Can you recreate how you were able to get it to work after using a python 3.8 environment? I had the same issue with python 3.9.5, but when I load a python 3.8 environment I still get the same error:

    (tensorflow-metal) ~ % python -V Python 3.8.10 (tensorflow-metal) ~ % pip install tensorflow-macos ERROR: Could not find a version that satisfies the requirement tensorflow-macos (from versions: none) ERROR: No matching distribution found for tensorflow-macos
  • How did you get Python 3.8? I am on Monterey release now and System python3 is 3.7: which python3 -> /usr/bin/python3; python3 --version ->  Python 3.7.3. Installing Python 3.8 from anaconda or python.org both still give me the error in the original post.

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
  • Python 3.8.5

  • Python 3.8.9 failed, but 3.8.2 worked as above.

  • According to Apple, you shall update to Monterey.

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
  • Hi! Thank you so much for your comment! I have MacBook Air on an Apple Silicon M1 chip and faced with the same problem described above. After downgrading to python 3.8.10 version, I finally installed both tensorflow-macos and tensorflow-metal libs. And I even can import check the TF version which is already a promising result :D

Add a Comment

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
  • This step was absolutely essential for me. Thanks. The first package is much larger than the first, I did them in two separate passes.

  • This worked for in Python3.9.7 virtual env, the problem is BigSur Version which complicates the package reading from pip. I suggest to containerize your package once installed and use it directly in your project site-packages. If you are enable to get this command work then, try to download the package manually and insert it into your project, that will definitely work.

Add a Comment

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?

  • Hi, @afaq187. Sorry, this thread is about Intel-based Mac devices, so I can't do anything more for you. However, from my experience, the latest version will cause kernel crashes while training. So my solution is to downgrade to the previous version. I hope this can help.

Add a Comment

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.

  • Seriously. I waited a year for the platform to work itself out but there seems to be a lot of issues still. Still outperforms my prior 10-year-old laptop!

Add a Comment

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.

Post not yet marked as solved Up vote reply of andi Down vote reply of andi

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

  • Intel-based is also supported. However, you have to specify the python version as the following instructions.

    `NOTE: If using conda environment built against pre-macOS 11 SDK use:

    SYSTEM_VERSION_COMPAT=0 python -m pip install tensorflow-macos otherwise you will get errors like : “not a supported wheel on this platform”`

  • Ummm, it just not working properly, seems like it can't recognize the GPU / the GPU doesn't support it? I'm new to it therefore I'm quite sure about what's going on.

Add a Comment

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】
  • It turns out this is because I didn't use the included python3.8(Python 3.8.12 (default, *, *)) Also you don't need that prefix as long as you use the default one.(Though this is kindof inconvenient since it's a part of the macOS system) Everything works fine now. @hawkiyc, Thank you so much.

Add a Comment

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.