Installation Error "zsh: illegal hardware instruction"

If normal installation fails for MacOS there may be an issue in the dependencies.
During my installation process I ran into the following problems:
- error could not build “grpcio” wheels
- xcrun error: invalid developer path
→ My xcode was not up to date
→ FIX: $ xcode-select --install
→ Found here
- xcrun: error: invalid active devel… | Apple Developer Forums
- Add instruction for building on macOS with M1 chip by Alyetama · Pull Request #30316 · grpc/grpc · GitHub

Once I got that sorted, everything was installed but upon running in python

import bayesflow as bf

I got the error:
“zsh: illegal hardware instruction”
This is a known error for tensorflow in M1 Chips. The way I got around this was following
this YouTube tutorial (https://www.youtube.com/watch?v=WFIZn6titnc) whose steps are abbreviated below.

Exact steps

  1. Download Miniforge
    1.1 Go to: GitHub - conda-forge/miniforge: A conda-forge distribution.
    1.2 Click to download current MacOS arm Miniforge file
    1.3 Find file name in Downloads folder and copy it
    /Users/username/Downloads/Miniforge3-MacOSX-arm64.sh
    1.4 Change file permissions to allow execution
    $ chmod +x /Users/username/Downloads/Miniforge3-MacOSX-arm64.sh
    1.5 Execute file

$ sh /Users/username/Downloads/Miniforge3-MacOSX-arm64.sh

  1. Activate Miniforge
    $ source ~/miniforge3/bin/activate
  2. Install tensorflow dependencies for apple
    $conda install -c apple tensorflow-deps
  3. Check that tensorflow is not already installed
    $ python -m pip uninstall tensorflow-macos
  4. Create a conda environment
    $ conda create --name bayes2
  5. Activate the environment
    $ conda activate bayes2
  6. Install dependencies and tensorflow into the environment
$ conda install -c apple tensorflow-deps
    $ pip install tensorflow-macos
  1. Install bayesflow as normal
    $ pip install bayesflow
4 Likes

Welcome to the BayesFlow Forums!

Thanks for sharing your solution to this issue. I’m sure that will help others who encounter the same problems at some point.

Cheers!