- 下载为m1优化的tensorflow及其插件
- https://github.com/apple/tensorflow_macos
- 点击INSTALLATION下的releases
- 下载asserts下的.tar.gz文件
创建一个新的conda python环境
在终端输入如下命令(python3.8是环境的名称):
conda create --name python3.8 python=3.8
创建好环境后使用以下命令切换到刚刚创建的环境中:
source activate python3.8
安装tensorflow ```
这里…替换成步骤2中安装的文件的路径(下同)
libs=”/Users/huang/Downloads/tensorflow_macos/arm64/“
将envname换成你自己创建环境时起的名字
env=”/Users/huang/miniforge3/envs/python3.8”
运行以下代码
conda upgrade -c conda-forge pip setuptools cached-property six
pip install —upgrade -t “$env/lib/python3.8/site-packages/“ —no-dependencies —force “$libs/grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl”
pip install —upgrade -t “$env/lib/python3.8/site-packages/“ —no-dependencies —force “$libs/h5py-2.10.0-cp38-cp38-macosx_11_0_arm64.whl”
pip install —upgrade -t “$env/lib/python3.8/site-packages/“ —no-dependencies —force “$libs/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl”
conda install -c conda-forge -y absl-py conda install -c conda-forge -y astunparse conda install -c conda-forge -y gast conda install -c conda-forge -y opt_einsum conda install -c conda-forge -y termcolor conda install -c conda-forge -y typing_extensions conda install -c conda-forge -y wheel conda install -c conda-forge -y typeguard
pip install tensorboard
pip install wrapt flatbuffers tensorflow_estimator google_pasta keras_preprocessing protobuf
这里要查看你下载的whl文件的版本,如何查看版本见下图
pip install —upgrade -t “$env/lib/python3.8/site-packages/“ —no-dependencies —force “$libs/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl” ```
- 查看whl文件的版本:
- 打开步骤2中下载的tensorflow_macos文件夹,在里面的arm64文件夹下有一个tensorflow_macos-(版本号)-…文件
- 根据不同的版本号修改上面的命令就好啦~若提示Successfully installed tensorflow-macos-...则安装成功。可以使用__version__查看tensorflow的版本