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

MacOS M1 Pro安装TensorFlow后导入报错求助

解决TensorFlow在macOS Monterey(M1 Pro)上的导入错误

错误原因

报错中缺失的_OBJC_CLASS_$_MPSGraphRandomOpDescriptor是MetalPerformanceShadersGraph框架中的类,该类仅在macOS 13.0(Ventura)及更高版本中提供。你当前使用的macOS Monterey(12.x)系统自带的框架版本不支持此API,导致TensorFlow的Metal插件加载失败。

解决方案

方案1:升级系统到macOS Ventura或更高版本(推荐)

这是最彻底的解决方式,后续TensorFlow的Metal功能支持会更完善:

  • 打开「系统设置」→「通用」→「软件更新」
  • 按照提示完成系统升级,重启后重新激活你的conda环境,即可正常导入TensorFlow。

方案2:降级TensorFlow到兼容Monterey的版本

如果暂时无法升级系统,可安装适配Monterey的TensorFlow版本(如2.11.x系列):

  1. 卸载当前环境中的TensorFlow相关组件:
    conda deactivate
    conda remove -n tensorflow tensorflow tensorflow-metal tensorflow-plugins
    
  2. 重新安装兼容版本:
    conda activate tensorflow
    conda install tensorflow=2.11 tensorflow-metal=0.7.0
    
  3. 验证安装:
    启动Python交互环境,执行以下命令:
    import tensorflow as tf
    print(tf.config.list_physical_devices('GPU'))
    
    若输出包含PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU'),则说明Metal加速已正常生效。

额外注意

确保你的conda环境是基于Apple Silicon架构(osx-arm64),可通过执行conda list查看包的架构列,所有TensorFlow相关包应为osx-arm64类型,避免混用x86架构的包导致冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 20:25:47