You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apple M1 Max运行TensorFlow报错的排查及解决方法

问题:M1 MAX芯片Mac上TensorFlow运行报错(numpy API版本不匹配)

环境配置

  • 设备:搭载Apple M1 MAX芯片的Mac
  • 系统:Monterey 12.6.1
  • 运行环境:Anaconda,Python 3.9.12
  • TensorFlow相关包版本:
python --version
Python 3.9.12

conda list | grep tensorflow
tensorflow-deps           2.8.0                         0    apple
tensorflow-estimator      2.10.0                   pypi_0    pypi
tensorflow-macos          2.10.0                   pypi_0    pypi
tensorflow-metal          0.6.0                    pypi_0    pypi

运行代码

from tensorflow.keras.models import Sequential
from tensorflow.keras.optimizers import Adam
from tensorflow.keras import layers

model = Sequential([layers.Input((3, 1)),
                    layers.LSTM(64),
                    layers.Dense(32, activation='relu'),
                    layers.Dense(32, activation='relu'),
                    layers.Dense(1)])

model.compile(loss='mse', 
              optimizer=Adam(learning_rate=0.001),
              metrics=['mean_absolute_error'])

model.fit(X_train, y_train, validation_data=(X_val, y_val), epochs=100)

报错信息

核心错误

RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xe

回溯信息

TypeError                                 Traceback (most recent call last)
Input In [14], in <cell line: 1>()
----> 1 from tensorflow.keras.models import Sequential
      2 from tensorflow.keras.optimizers import Adam
      3 from tensorflow.keras import layers

该报错仅在M1 MAX芯片的Mac上出现,2020款M1芯片的Mac mini(Monterey 12.6系统)及Win11系统中运行相同代码无异常,怀疑是环境或芯片适配问题。目标是成功构建模型并完成训练数据拟合。

解决步骤

通过以下操作解决了依赖冲突及numpy版本不匹配问题:

  • 卸载keras:pip uninstall keras
  • 卸载keras-preprocessing:pip uninstall keras-preprocessing
  • 卸载tensorboard:pip uninstall tensorboard
  • 升级numpy:pip install --upgrade numpy
  • 若升级numpy失败,先卸载再重新安装:pip uninstall numpy && pip install numpy
  • 重新安装tensorflow-macos:python -m pip install tensorflow-macos

内容的提问来源于stack exchange,提问作者Egypt CCI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 23:01:13