MacOS M1 安装tensorflow

通过miniforge安装tensorflow

  1. 安装miniforge:
  • 如果已有anaconda可以先卸载
# 删除conda环境
rm -rf ~/miniforge3
rm -rf .conda
rm -rf .condarc
# 执行以下内容
bash Miniforge3-MacOSX-arm64.sh
  • 配置yml安装依赖文件
  name: apple_tensorflow
  channels:
    - conda-forge
    - nodefaults
  dependencies:
    - grpcio
    - h5py
    - ipython
    - numpy
    - pip=20.2.4
    - python=3.8
    - scipy
    - termcolor
    - typeguard
    - wheel
    - absl-py
    - astunparse
    - python-flatbuffers
    - gast
    - google-pasta
    - keras-preprocessing
    - opt_einsum
    - protobuf
    - tensorboard
    - tensorflow-estimator
    - termcolor
    - typing_extensions
    - wrapt
  • 创建conda环境
conda env create --file=PATH_TO_ENVIRONMENT.YML --name=YOUR_ENV_NAME
# 激活
conda activate YOUR_ENV_NAME
  • 安装tensorflow
pip install --upgrade --force --no-dependencies https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl

https://medium.com/gft-engineering/macbook-m1-tensorflow-on-jupyter-notebooks-6171e1f48060# (全文可参见此处)
https://www.cnblogs.com/dangui/p/15128418.html#1-下载arm版miniforge3
https://github.com/apple/tensorflow_macos/issues/153
苹果官方(macos 12+安装方法, 2.5不行可以试试2.6)https://developer.apple.com/metal/tensorflow-plugin/
最全地址:https://github.com/apple/tensorflow_macos
系统版本:https://zhuanlan.zhihu.com/p/386164537
找不到tensorflow-macos或者metal的情况下,这样安装 https://developer.apple.com/forums/thread/683757

问题:

  1. 依赖冲突,可以带上参数:pip install tensorflow-macos --force --no-dependencies
  2. AlreadyExistsError(tensorflow 2.6.0):错误原因是因为tensorflow和keras版本不匹配,运行pip install keras==2.6.0 可解决问题
  3. 找不到各种方法,可以查看tensorflow 官方api: https://www.tensorflow.org/versions

卸载conda

https://blog.csdn.net/weixin_37272286/article/details/115303269

原文地址:https://www.cnblogs.com/practitioners/p/15514567.html