python-3.x - 为什么在 Mac 上加载 tensorflow 会导致 "Process finished with exit code 132 (interrupted by signal 4: SIGILL)"?

标签 python-3.x macos tensorflow

我使用的是配备 M1 处理器的 MacBook Pro,macOS 版本 11.0.1,PyCharm 中的 Python 3.8,Tensorflow 版本 2.4.0rc4(也尝试过 2.3.0、2.3.1、2.4.0rc0)。我正在尝试运行以下代码:

import tensorflow
这会导致错误消息:
Process finished with exit code 132 (interrupted by signal 4: SIGILL)
代码在我的 Windows 和 Linux 机器上运行良好。
错误消息是什么意思,我该如何解决?

最佳答案

似乎当您安装了多个 python 解释器时会发生这个问题,其中一些是针对不同的架构师(x86_64 vs arm64)。您需要确保使用了正确的 python 解释器,如果您安装了 Apple 的 tensorflow 版本,那么这可能需要一个 arm64 解释器。
如果您使用 rosetta(Apple 的 x86_64 模拟器),那么您需要使用 x86_64 python 解释器,如果您以某种方式加载 arm64 python 解释器,您将收到非法指令错误(这是完全有道理的)。
如果您使用任何安装新 python 解释器的脚本,那么您需要确保安装了正确的架构解释器(很可能是 arm64)。
总的来说,我认为这个问题的发生是因为 python 环境设置不是为可以运行多个指令集/架构的系统设置的,pip 确实检查了包的架构和主机系统,但似乎你可以运行一个 x86_64 解释器来加载一个包arm64,这会产生问题。
作为引用,人们可以检查 tensorflow_macos 中的 issue

关于python-3.x - 为什么在 Mac 上加载 tensorflow 会导致 "Process finished with exit code 132 (interrupted by signal 4: SIGILL)"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65242614/

相关文章:

python - 无法从 Python3 打开到 PostgreSQL 的连接

python - 使用 lambda、map 和 list 时,如果 Boolean 为 True,如何返回以下位置的列表?

ruby-on-rails - 每秒 MacOS 唤醒错误

tensorflow - 优化器类中 tensorflow minimum() 函数中的 "gate_gradients"属性是什么?

python - 使用 tf.optimizer.Adam 来最小化 Tensorflow Core 2 alpha 中变量的损失的正确方法

python-3.x - Azure Cli - 如何显示 API 的操作后端(HTTPs 端点)信息

python - 卡住骰子滚动?

xcode - 在 Swift 2.0 中更改 NSView 的背景颜色

objective-c - NSOutlineView——组合多个源

python - 没有 NVIDIA 的 Tensorflow-GPU,可能吗?