前置条件:homebrew
1.在终端输入命令行,安装mini forge.
brew install miniforge
2.创建tensorflow运行环境,同时在该运行环境中安装python,截止2023年7月26日,tensorflow支持到python3.11以前的版本。
conda create -n tf "python<3.11"
3.进入创建的tensorflow运行环境。
conda activate tf
4.安装apple tensorflow-deps
conda install -c apple tensorflow-deps
5.更新pip,安装tensorflow-macos
pip install --upgrade pip
pip install tensorflow-macos
6.安装Metal-plugin
pip install tensorflow-metal
7.安装tensorflow-dataset
pip install tensorflow_datasets
8.安装Jupyterlab
conda install jupyterlab -y
9.安装其他运行库
pip install numpy --upgrade pip install pandas --upgrade pip install matplotlib --upgrade pip install scikit-learn --upgrade pip install scipy --upgrade pip install plotly --upgrade
pip install transformers datasets --upgrade
10.检查GPU支持
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))