Installing tflit_micro on macOS with M1 chip

I am working through the book “TinyML : Machine Learning with TensorFlow Lite on Arduino and Ultra-Low-Power Microcontrollers”.
However, I am failing to use tflite-micro on my MacOS with M1 chip, for example in order to use its interpreter:

from tflite_micro.python.tflite_micro import runtime
tflm_interpreter = runtime.Interpreter.from_file(model_path)

My platform is the following

  • macOS: 13.4.1
  • Python Platform: macOS-13.4.1-arm64-arm-64bit
  • Python 3.10.13 (main, Sep 11 2023, 08:16:02) [Clang 14.0.6 ]
  • Tensor Flow Version: 2.15.0

Concretely, I am working with a conda environment and in order to use the gpu on my Mac I have installed tensorflow with the following:

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

I have tried to pip install tflite-micro with

pip install tflite-micro

which yields

ERROR: Could not find a version that satisfies the requirement tflite-micro (from versions: none)
ERROR: No matching distribution found for tflite-micro

I have also cloned the repo https://github.com/tensorflow/tflite-microand then tried to build it with

bazel build //python/tflite_micro:whl.dist

as described in https://github.com/tensorflow/tflite-micro/tree/main/python/tflite_micro

Yet, this yields various error messages (see below). I tried also different version of python and tensorflow, but never managed to get it running. I am happy about any help.

Starting local Bazel server and connecting to it...
INFO: Repository tflm_pip_deps_tensorflow instantiated at:
  /Users/johndoe/projects/tflite-micro/WORKSPACE:55:13: in <toplevel>
  /private/var/tmp/_bazel_johndoe/89f2d396ebe8ba2f38d77eed723be11e/external/tflm_pip_deps/requirements.bzl:49:20: in install_deps
Repository rule whl_library defined at:
  /private/var/tmp/_bazel_johndoe/89f2d396ebe8ba2f38d77eed723be11e/external/rules_python/python/pip_install/pip_repository.bzl:715:30: in <toplevel>
ERROR: An error occurred during the fetch of repository 'tflm_pip_deps_tensorflow':
   Traceback (most recent call last):
	File "/private/var/tmp/_bazel_johndoe/89f2d396ebe8ba2f38d77eed723be11e/external/rules_python/python/pip_install/pip_repository.bzl", line 691, column 13, in _whl_library_impl
		fail("whl_library %s failed: %s (%s) error code: '%s'" % (rctx.attr.name, result.stdout, result.stderr, result.return_code))
Error in fail: whl_library tflm_pip_deps_tensorflow failed:  (ERROR: Could not find a version that satisfies the requirement tensorflow==2.15.0.post1 (from versions: 2.13.0rc0, 2.13.0rc1, 2.13.0rc2, 2.13.0, 2.13.1, 2.14.0rc0, 2.14.0rc1, 2.14.0, 2.14.1, 2.15.0rc0, 2.15.0rc1, 2.15.0, 2.16.0rc0)
ERROR: No matching distribution found for tensorflow==2.15.0.post1
Traceback (most recent call last):
  File "/Users/johndoe/miniconda3/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/johndoe/miniconda3/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/private/var/tmp/_bazel_johndoe/89f2d396ebe8ba2f38d77eed723be11e/external/rules_python/python/pip_install/tools/wheel_installer/wheel_installer.py", line 452, in <module>
    main()
  File "/private/var/tmp/_bazel_johndoe/89f2d396ebe8ba2f38d77eed723be11e/external/rules_python/python/pip_install/tools/wheel_installer/wheel_installer.py", line 429, in main
    subprocess.run(pip_args, check=True, env=env)
  File "/Users/johndoe/miniconda3/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/Users/johndoe/miniconda3/bin/python3', '-m', 'pip', '--isolated', 'wheel', '--no-deps', '-r', '/var/folders/p_/vfh7y12x2j90z151vdrjb_d0sbdt0z/T/tmpypbgebmo']' returned non-zero exit status 1.
) error code: '1'
ERROR: /Users/johndoe/projects/tflite-micro/WORKSPACE:55:13: fetching whl_library rule //external:tflm_pip_deps_tensorflow: Traceback (most recent call last):
	File "/private/var/tmp/_bazel_johndoe/89f2d396ebe8ba2f38d77eed723be11e/external/rules_python/python/pip_install/pip_repository.bzl", line 691, column 13, in _whl_library_impl
		fail("whl_library %s failed: %s (%s) error code: '%s'" % (rctx.attr.name, result.stdout, result.stderr, result.return_code))
Error in fail: whl_library tflm_pip_deps_tensorflow failed:  (ERROR: Could not find a version that satisfies the requirement tensorflow==2.15.0.post1 (from versions: 2.13.0rc0, 2.13.0rc1, 2.13.0rc2, 2.13.0, 2.13.1, 2.14.0rc0, 2.14.0rc1, 2.14.0, 2.14.1, 2.15.0rc0, 2.15.0rc1, 2.15.0, 2.16.0rc0)
ERROR: No matching distribution found for tensorflow==2.15.0.post1
Traceback (most recent call last):
  File "/Users/johndoe/miniconda3/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/johndoe/miniconda3/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/private/var/tmp/_bazel_johndoe/89f2d396ebe8ba2f38d77eed723be11e/external/rules_python/python/pip_install/tools/wheel_installer/wheel_installer.py", line 452, in <module>
    main()
  File "/private/var/tmp/_bazel_johndoe/89f2d396ebe8ba2f38d77eed723be11e/external/rules_python/python/pip_install/tools/wheel_installer/wheel_installer.py", line 429, in main
    subprocess.run(pip_args, check=True, env=env)
  File "/Users/johndoe/miniconda3/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/Users/johndoe/miniconda3/bin/python3', '-m', 'pip', '--isolated', 'wheel', '--no-deps', '-r', '/var/folders/p_/vfh7y12x2j90z151vdrjb_d0sbdt0z/T/tmpypbgebmo']' returned non-zero exit status 1.
) error code: '1'
ERROR: no such package '@@tflm_pip_deps_tensorflow//': whl_library tflm_pip_deps_tensorflow failed:  (ERROR: Could not find a version that satisfies the requirement tensorflow==2.15.0.post1 (from versions: 2.13.0rc0, 2.13.0rc1, 2.13.0rc2, 2.13.0, 2.13.1, 2.14.0rc0, 2.14.0rc1, 2.14.0, 2.14.1, 2.15.0rc0, 2.15.0rc1, 2.15.0, 2.16.0rc0)
ERROR: No matching distribution found for tensorflow==2.15.0.post1
Traceback (most recent call last):
  File "/Users/johndoe/miniconda3/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/johndoe/miniconda3/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/private/var/tmp/_bazel_johndoe/89f2d396ebe8ba2f38d77eed723be11e/external/rules_python/python/pip_install/tools/wheel_installer/wheel_installer.py", line 452, in <module>
    main()
  File "/private/var/tmp/_bazel_johndoe/89f2d396ebe8ba2f38d77eed723be11e/external/rules_python/python/pip_install/tools/wheel_installer/wheel_installer.py", line 429, in main
    subprocess.run(pip_args, check=True, env=env)
  File "/Users/johndoe/miniconda3/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/Users/johndoe/miniconda3/bin/python3', '-m', 'pip', '--isolated', 'wheel', '--no-deps', '-r', '/var/folders/p_/vfh7y12x2j90z151vdrjb_d0sbdt0z/T/tmpypbgebmo']' returned non-zero exit status 1.
) error code: '1'
ERROR: /Users/johndoe/projects/tflite-micro/tensorflow/lite/tools/BUILD:3:11: //tensorflow/lite/tools:flatbuffer_utils depends on @@tflm_pip_deps_tensorflow//:pkg in repository @@tflm_pip_deps_tensorflow which failed to fetch. no such package '@@tflm_pip_deps_tensorflow//': whl_library tflm_pip_deps_tensorflow failed:  (ERROR: Could not find a version that satisfies the requirement tensorflow==2.15.0.post1 (from versions: 2.13.0rc0, 2.13.0rc1, 2.13.0rc2, 2.13.0, 2.13.1, 2.14.0rc0, 2.14.0rc1, 2.14.0, 2.14.1, 2.15.0rc0, 2.15.0rc1, 2.15.0, 2.16.0rc0)
ERROR: No matching distribution found for tensorflow==2.15.0.post1
Traceback (most recent call last):
  File "/Users/johndoe/miniconda3/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/johndoe/miniconda3/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/private/var/tmp/_bazel_johndoe/89f2d396ebe8ba2f38d77eed723be11e/external/rules_python/python/pip_install/tools/wheel_installer/wheel_installer.py", line 452, in <module>
    main()
  File "/private/var/tmp/_bazel_johndoe/89f2d396ebe8ba2f38d77eed723be11e/external/rules_python/python/pip_install/tools/wheel_installer/wheel_installer.py", line 429, in main
    subprocess.run(pip_args, check=True, env=env)
  File "/Users/johndoe/miniconda3/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/Users/johndoe/miniconda3/bin/python3', '-m', 'pip', '--isolated', 'wheel', '--no-deps', '-r', '/var/folders/p_/vfh7y12x2j90z151vdrjb_d0sbdt0z/T/tmpypbgebmo']' returned non-zero exit status 1.
) error code: '1'
ERROR: Analysis of target '//python/tflite_micro:whl.dist' failed; build aborted: Analysis failed
INFO: Elapsed time: 6.185s, Critical Path: 2.91s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
FAILED: 
    Fetching repository @@tflm_pip_deps_numpy; starting
    Fetching repository @@numpy_cc_deps; Restarting.Preformatted text