M1配置miniforge3+TensorFlow 方法
前期踩坑
anaconda安装完虚拟环境,配置好TensorFlow后,不支持import tensorflow,会报硬件错误,具体原因我也不清楚,看了教程说用miniforge3可以兼容,但是看了很多教程弄了一天还是失败,最头疼的是安装TensorFlow各种依赖的时候报各种错。
apple官方给出方案
如果你看了国内的各种方案配置的miniforge3还失败了,建议直接删除用户目录下的miniforge3,然后根据以下方法配置。
https://developer.apple.com/metal/tensorflow-plugin/
Step 1: Environment setup
arm64 : Apple Silicon
- 下载并安装 Conda env:
https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
- 安装TensorFlow 依赖:
conda install -c apple tensorflow-deps
- 更新TensorFlow:
# uninstall existing tensorflow-macos and tensorflow-metal
python -m pip uninstall tensorflow-macos
python -m pip uninstall tensorflow-metal
# Upgrade tensorflow-deps
conda install -c apple tensorflow-deps --force-reinstall
# or point to specific conda environment
conda install -c apple tensorflow-deps --force-reinstall -n my_env
- tensorflow-deps 版本遵循TensorFlow基础版本:
For v2.5:
conda install -c apple tensorflow-deps==2.5.0
For v2.6:
conda install -c apple tensorflow-deps==2.6.0
NOTE: python versions 3.8 and 3.9 supported
Step 2: 安装base TensorFlow
python -m pip install tensorflow-macos
Step 3: 安装tensorflow-metal 插件
Install tensorflow-metal plugin