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

岁酱吖の 提交于 2021-02-20 02:25:40

问题


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?


回答1:


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.




回答2:


  1. Try to use anaconda for your venv
  2. create conda venv and activate

conda create -n tensor python=3.8

conda activate tensor

  1. install packages

conda install -c conda-forge tensorflow

  1. run pycharcharm
  2. apply enviroment to pycharm(interpreter needs to be pointed properly to this new venv)
  3. import tensorflow wait for skeleton to load then try to run import
  4. if you want to avoid conda you may try pip install tensorflow --no-binary :all:

I didnt try it, as conda done job for me



来源:https://stackoverflow.com/questions/65242614/why-does-loading-tensorflow-on-mac-lead-to-process-finished-with-exit-code-132

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!