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

MacBook Air M1如何无需虚拟环境全局安装可正常运行的TensorFlow

MacBook Air M1 全局无虚拟环境安装TensorFlow解决方案

错误原因说明

你遇到的zsh: illegal hardware instruction报错,是因为当前安装的TensorFlow 2.6为x86架构编译版本,未适配M1系列的arm64架构,无法在原生arm环境下正常运行。

操作步骤

第一步:清理现有残留TensorFlow包

先完全卸载当前安装的所有TensorFlow相关组件,避免版本冲突:

pip3 uninstall -y tensorflow tensorflow-estimator tensorflow-macos tensorflow-metal

第二步:确认Python架构适配M1

运行以下命令验证你当前使用的Python是适配M1的arm64版本:

file $(which python3)

如果输出结果包含arm64字样则符合要求,若显示为x86_64,需要先重新安装适配arm64架构的Python 3.9版本。

第三步:全局安装适配M1的TensorFlow

苹果官方已推出适配Apple Silicon的TensorFlow版本,直接全局安装即可,因目标路径为系统级Python目录,需要加sudo获取权限:

sudo pip3 install tensorflow-macos tensorflow-metal

如果下载速度较慢,可以追加国内镜像源参数:

sudo pip3 install tensorflow-macos tensorflow-metal -i https://pypi.tuna.tsinghua.edu.cn/simple

第四步:验证安装结果

运行以下命令验证TensorFlow可正常调用,且GPU加速生效:

python3 -c "import tensorflow as tf; print('TensorFlow版本:', tf.__version__); print('可用GPU设备:', tf.config.list_physical_devices('GPU'))"

无报错且能正常输出版本号和GPU设备信息,即为安装成功,后续无需激活虚拟环境可直接调用TensorFlow。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 18:09:03