M1 Mac安装TensorFlow时wrapt编译失败及conda通道问题求助
M1 Mac Miniforge3环境TensorFlow安装问题解决指南
一、先修复conda通道异常
强制重置conda通道配置,解决无法移除conda-forge、更新失败的问题:
- 执行命令:
conda config --remove-key channels - 重新添加默认通道:
conda config --add channels defaults - 设置通道严格优先级:
conda config --set channel_priority strict - 测试更新:
conda update --all
- 执行命令:
若上述操作无效,直接删除配置文件重建:
- 删除配置文件:
rm ~/.condarc - 重新初始化conda:
conda init zsh(使用bash则替换为conda init bash)
- 删除配置文件:
二、最稳妥的M1适配TensorFlow安装方案(避开编译坑)
Python3.11在M1平台上的wrapt编译兼容性尚未完全成熟,建议切换到Python3.10环境走官方适配路线:
- 创建干净的conda环境:
conda create -n tf_env python=3.10- 激活环境:
conda activate tf_env
- 添加苹果官方适配通道:
conda config --add channels appleconda config --add channels conda-forge
- 按顺序安装依赖与TensorFlow:
conda install -c apple tensorflow-depspip install tensorflow-macospip install tensorflow-metal(启用M1 GPU加速)
三、坚持用Python3.11的临时解决办法
- 查看当前Python的平台标签:
python -c "import sysconfig; print(sysconfig.get_platform())" - 下载对应版本的wrapt预编译wheel包(例如
wrapt-1.15.0-cp311-cp311-macosx_11_0_arm64.whl) - 本地安装该wheel包:
pip install /你下载的wheel文件路径/wrapt-xxx.whl - 再执行TensorFlow安装:
pip install tensorflow-macos
四、验证安装结果
激活环境后运行以下代码:
import tensorflow as tf print(tf.__version__) print(tf.config.list_physical_devices('GPU'))
能正常输出版本号和GPU设备信息,即为安装成功。
内容的提问来源于stack exchange,提问作者Jahnavi
相关产品推荐
相关产品推荐

