Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does loading tensorflow on Mac lead to "Process finished with exit code 132 (interrupted by signal 4: SIGILL)"?

I am using a MacBook Pro with M1 processor, macOS version 11.0.1, Python 3.8 in PyCharm, Tensorflow version 2.4.0rc4 (also tried 2.3.0, 2.3.1, 2.4.0rc0). I am trying to run the following code:

import tensorflow

This causes the error message:

Process finished with exit code 132 (interrupted by signal 4: SIGILL)

The code runs fine on my Windows and Linux machines. What does the error message mean and how can I fix it?

like image 398
user505117 Avatar asked Dec 10 '20 21:12

user505117


2 Answers

Seems that this problem happens when you have multiple python interpreters installed, and some of them are for differente architectuers (x86_64 vs arm64). You need to make sure that the correct python interpreter is being used, if you installed Apple's version of tensorflow, then that probably requires an arm64 interpreter.

If you use rosetta (Apple's x86_64 emulator) then you need to use a x86_64 python interpreter, if you somehow load the arm64 python interpreter, you will get the illegal instruction error (which totally makes sense).

If you use any script that installs new python interpreters, then you need to make sure the correct interpreter for the architecture is installed (most likely arm64).

Overalll I think this problem happens because the python environment setup is not made for systems that can run multiple instruction sets/architectures, pip does check the architecture of packages and the host system but seems you can run a x86_64 interpreter to load a package meant for arm64 and this produces the problem.

For reference there is an issue in tensorflow_macos that people can check.

like image 111
Dr. Snoopy Avatar answered Sep 28 '22 06:09

Dr. Snoopy


I have been able to resolve this issue by using Miniforge instead of Anaconda as the Python environment. Anaconda doesn't support the arm64 architecture, yet.

like image 21
martin_wun Avatar answered Sep 28 '22 07:09

martin_wun