问题
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:
- Try to use anaconda for your venv
- create conda venv and activate
conda create -n tensor python=3.8
conda activate tensor
- install packages
conda install -c conda-forge tensorflow
- run pycharcharm
- apply enviroment to pycharm(interpreter needs to be pointed properly to this new venv)
- import tensorflow wait for skeleton to load then try to run import
- 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