How do I install the Tensorflow module on a M4 MacBookPro with Apple Silicon?

I have followed instructions from ChatGPT on getting Tensorflow to run on Apple Silicon but it wasn’t successful.


I get the following results in Terminal.

>>> import tensorflow as tf
2025-04-17 16:34:22.387575: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE4.1 SSE4.2, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/tensorflow/__init__.py", line 51, in <module>
    from ._api.v2 import compat
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/tensorflow/_api/v2/compat/__init__.py", line 37, in <module>
    from . import v1
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/tensorflow/_api/v2/compat/v1/__init__.py", line 31, in <module>
    from . import compat
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/tensorflow/_api/v2/compat/v1/compat/__init__.py", line 37, in <module>
    from . import v1
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/tensorflow/_api/v2/compat/v1/compat/v1/__init__.py", line 48, in <module>
    from tensorflow._api.v2.compat.v1 import lite
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/tensorflow/_api/v2/compat/v1/lite/__init__.py", line 9, in <module>
    from . import experimental
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/tensorflow/_api/v2/compat/v1/lite/experimental/__init__.py", line 8, in <module>
    from . import authoring
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/tensorflow/_api/v2/compat/v1/lite/experimental/authoring/__init__.py", line 8, in <module>
    from tensorflow.lite.python.authoring.authoring import compatible
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/tensorflow/lite/python/authoring/authoring.py", line 43, in <module>
    from tensorflow.lite.python import convert
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/tensorflow/lite/python/convert.py", line 27, in <module>
    from tensorflow.lite.python import util
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/tensorflow/lite/python/util.py", line 52, in <module>
    from jax import xla_computation as _xla_computation
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/jax/__init__.py", line 25, in <module>
    from jax._src.cloud_tpu_init import cloud_tpu_init as _cloud_tpu_init
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/jax/_src/cloud_tpu_init.py", line 17, in <module>
    from jax._src import config
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/jax/_src/config.py", line 27, in <module>
    from jax._src import lib
  File "/opt/anaconda3/envs/tf-metal/lib/python3.9/site-packages/jax/_src/lib/__init__.py", line 84, in <module>
    cpu_feature_guard.check_cpu_features()
RuntimeError: This version of jaxlib was built using AVX instructions, which your CPU and/or operating system do not support. This error is frequently encountered on macOS when running an x86 Python installation on ARM hardware. In this case, try installing an ARM build of Python. Otherwise, you may be able work around this issue by building jaxlib from source.

hi @anon88576143

See if this links helps

Try to match with version of python, tensorflow and your system configuration settings

this is another link which should help you address issue with jax

I remember even for my macos, I had to download some lib separately

Hello, Stephen @anon88576143,

I don’t use M4, but I could share how I would deal with it.

First, I would start from the last line of the error message:

RuntimeError: This version of jaxlib was built using AVX instructions, which your CPU and/or operating system do not support. This error is frequently encountered on macOS when running an x86 Python installation on ARM hardware. In this case, try installing an ARM build of Python. Otherwise, you may be able work around this issue by building jaxlib from source.

Then, I would get a count of Pythons I have. For example, your Mac OS should come with one. Your anaconda has one.

Then, for each of them, check if it is a ARM build (as suggested by the error message). To do so, I believe we can run the following code on each of the Pythons:

Mine is “x86_64”.

Third, I would read this Anaconda article and the stackoverflow discussion shared by Deepti, and from which if I catch any important keywords, I would further google for more texts.

Then, come up with a list of actionables sorted by complexity and likelihood to success, and carry them out one by one on one or more Pythons in below, sorted by preference:

  1. Virtual environment created with the Anaconda’s Python or Virtual environment created with the MacOS’s Python;
  2. Anaconda’s Python.

Good thing of virtual environment is that we wouldn’t do irreversible damage. The worst would be to remove the virtual environment and start over. It is similar for Anaconda because you can always reinstall a fresh copy of it. However, never work on MacOS’s native Python directly because messing it up may cause some system feature to fail.

I have both Anaconda and MacOS in the list’s number 1 just in case the MacOS is already ARM built, otherwise, I would focus on Anaconda.

Lastly, the error message led me to believe that ARM build python might be necessary or a straight path, but the two links seem not relying on ARM build, so I will do that platform.machine() check to see what’s on the table, but start with easier actionables first (like ignore ARM build if I don’t have one already) on a virtual environment.

Cheers,
Raymond

Thanks Raymond.

Did you get past this?

I just installed successfully on an M4 MB Air using the steps on this Apple Developer page

I used a brand new install of mini forge and Conda to create the virtual environment. That is, instead of this step shown

python3 -m venv ~/venv-metal
source ~/venv-metal/bin/activate

I did this

conda create --name nlp python=3.12
conda activate nlp

which forced the python version installed there to be python=3.12. (doesn’t seem to be a TensorFlow wheel that works with python=3.13 on arm64)

Otherwise, followed the steps on that page. Running the example model from the linked page right now…

I use mini forge because it is lighter weight than Anaconda, and I am under the impression that its license is more friendly.

I don’t have active code that uses Jax but the installation from this page seemed to run as expected. Accelerated JAX on Mac - Metal - Apple Developer though see the caveats regarding arm64 here Installation — JAX documentation

I could at least get this much running…

Hope this helps

I did it without mini forge, conda or jax.

Thanks for posting your solution.