M1的mac电脑安装tensorflow
一、背景
最近新入手了M1的mac电脑,版本号为12.2,然后配置tensorflow,才发现按照原来的anconda创建虚拟环境再安装tensorflow最后会提示失败,查了大量的文档后,最终找到了解决方案,直接上攻略。
二、过程
1、下载 https://link.zhihu.com/?target=https%3A//github.com/conda-forge/miniforge/%23download, 选择 Miniforge3-MacOSX-arm64
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
2、创建一个conda环境
conda create -n tf26 python=3.8
3、安装Tensorflow
激活刚才建的虚拟环境
conda activate tf26
4、依赖包tensorflow-deps的安装步骤
详细的步骤见 apple开发者官网
1. conda install -c apple tensorflow-deps
# 指定定版本安装
2. conda install -c apple tensorflow-deps==2.6.0
5、安装tensorflow
python -m pip install tensorflow-macos -i https://pypi.tuna.tsinghua.edu.cn/simple
# 会有个报错, 自己安装下 pip install torch 然后再重新执行一遍
python -m pip install tensorflow-macos -i https://pypi.tuna.tsinghua.edu.cn/simple
6、安装tensorflow-metal
python -m pip install tensorflow-metal -i https://pypi.tuna.tsinghua.edu.cn/simple
上述的镜像也可以是豆瓣,百度源