2025, Oct 03 11:00

TensorFlow Import Crash on macOS ARM with Python 3.11: PyArrow-Protobuf Conflict and a Reliable Workaround

Importing TensorFlow on macOS ARM with Python 3.11 may crash with 'mutex lock failed'. See how PyArrow/Protobuf conflicts cause it; apply TensorFlow 2.19 fix.

Importing TensorFlow on macOS ARM with Python 3.11 can crash the interpreter with a thread-locking error or freeze a Jupyter kernel. The symptom appears immediately on a bare import, which makes the failure both surprising and hard to diagnose from user code. Below is a concise walkthrough of what happens, why it happens, and a safe way to proceed.

Minimal repro

The failure manifests even with the smallest possible import. To keep things explicit, here is a minimal snippet that triggers the same code path via importlib.

import importlib as module_loader
pkg_tf = module_loader.import_module("tensorflow")

In a standard REPL this can end the process with a C++ runtime error.

libc++abi: terminating due to uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument

In a Jupyter Notebook the kernel may hang indefinitely after running the import cell.

What is actually going on

During import, TensorFlow pulls in PyArrow. PyArrow depends on Protobuf. In the affected setup, the Protobuf integration on macOS leads to a conflict that trips a low-level mutex error. There is active discussion around this interaction, including details about TensorFlow 2.20 and PyArrow both using Protobuf without properly hidden symbols, and TensorFlow having upgraded its Protobuf version enough to make the symbol clash matter. The end result is a runtime crash during import.

Two public threads track the underlying problems and their resolution paths: apache/arrow#40088 and tensorflow/tensorflow#98563. A related discussion can also be found here: UKPLab/sentence-transformers#34919.

Confirmed workaround

The practical path forward today is to use TensorFlow 2.19.x. With that version in place, the import completes without the mutex crash on macOS ARM with Python 3.11.

import importlib as module_loader
pkg_tf = module_loader.import_module("tensorflow")
print(getattr(pkg_tf, "__version__", "unknown"))

This keeps the runtime stable while the upstream issues linked above converge on a fix.

Why this matters

Crashes on import are a red flag in production environments because they are not guarded by Python exceptions and they bypass ordinary error handling. In this case, the problem crosses project boundaries: TensorFlow, PyArrow, and Protobuf interact at the native layer, and symbol visibility across those binaries directly impacts interpreter stability. For anyone maintaining reproducible environments, this is a reminder that version alignment across transitive C/C++ dependencies is just as important as top-level Python package versions.

Takeaways

If you hit a mutex lock failed: Invalid argument crash importing TensorFlow 2.20.0 on macOS ARM with Python 3.11, the issue stems from the TensorFlow–PyArrow–Protobuf combination. Moving to TensorFlow 2.19.x restores a working setup. Keep an eye on the ongoing threads at apache/arrow#40088 and tensorflow/tensorflow#98563 for upstream fixes, and pin versions to avoid reintroducing the conflict while the resolution is in progress.

The article is based on a question from StackOverflow by Mikko Ohtamaa and an answer by Mikko Ohtamaa.