'Illegal instruction: 4 when importing tensorflow in python 3.6

I installed Tensorflow on macOS with Virtualenv. Everything went okay ("Successfully installed six-1.11.0 tensorflow-1.6.0" is the last output of the terminal, once i run the command pip3 install --upgrade tensorflow). So, with the virtualenv activated, I typed: python3 and then import tensorflow as tf but it outputs the error Illegal instruction: 4 and quits python.

I looked around to see if anybody else had encountered the same issue, but I didn't find much, apart from this question, which doesn't provide a solution. I read this answer explaining what Illegal instruction means, the point is that I'm on the latest version of macOS High Sierra:

enter image description here

Am I misunderstanding what the answer is referring to?

Do you know how I could solve this issue? Or hopefully a workaround, so that I can start using tensorflow.

Thank you in advance.



Solution 1:[1]

I had the same issue, so what I did was uninstalled tensorflow 1.6. installed

pip install -Iv tensorflow==1.5
pip install -Iv numpy==1.13

seems to be fine now, my guess is there was the latest bug in tensorflow 1.6.

To make sure it's compatible with the pandas, you can do: pip install -Iv numpy==1.13.3

Solution 2:[2]

It could not find 1.15 version for me as for @dfresh22, but that helped:

pip3 uninstall tensorflow
pip3 install -Iv tensorflow==1.5

Solution 3:[3]

Similarly, on Apple M1 with BigSur (Python 3.9), the Anaconda interface did complain about incompatible version of tensorflow for Python 3.9, pip did install from the terminal but I got "illegal instruction:4" message. Finally, the following command sorted out the necessary packages to install:

conda install conda-forge::tensorflow

the detail is here. This installation is an older version of tensorflow: tensorflow-2.7.0 .

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jose Garza
Solution 2 caffeinum
Solution 3