7

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.

Jules
  • 571
  • 2
  • 5
  • 12
  • figure it out? yet I am experiencing same thing, i see you installed 1.6 me too. I will revert back to 1.5 and see – dfresh22 Mar 07 '18 at 06:00
  • so I installed 1.15, and I was getting a warning about deprecating features in numpy. so after installing tensorflow 1.15, I installed numpy 1.13. everything works ok now – dfresh22 Mar 07 '18 at 06:06
  • error was: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`. from ._conv import register_converters as _register_converters – dfresh22 Mar 07 '18 at 06:06
  • It seems to be working on my end as well. Plus, since it is in a virtualenv the rest of my machine still has the latest numpy version. Thank you so much for the help! It’s the workaround I was looking for. So if you’d like, you could write an answer so that I can mark it as the correct one – Jules Mar 07 '18 at 06:47
  • thanks, i added an answer – dfresh22 Mar 07 '18 at 07:17

3 Answers3

6

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

dfresh22
  • 961
  • 1
  • 15
  • 23
3

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

pip3 uninstall tensorflow
pip3 install -Iv tensorflow==1.5
caffeinum
  • 401
  • 5
  • 13
2

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 .

Mahmut ARIKAN
  • 615
  • 8
  • 7
  • I am on MacBook M2 pro max and this conda install is the only thing that worked for me. None of the pip installation commands work as after when I try to import tensorflow I get the Illegal instruction: 4 error all the time. Strange that tenforflow officially recommend to use pip when it doesn't work for Mac. – Katya Apr 29 '23 at 18:19