在 Apple 硅 M1 上 python3 安装 Tensorflow [英] python3 install of Tensorflow on Apple silicon M1

查看:67
本文介绍了在 Apple 硅 M1 上 python3 安装 Tensorflow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Apple Silicon M1 上安装了 macOS Big Sur,但无法在 python3 中安装 Tensorflow.我删除了 xcode python3 并安装了 brew arm64 python3(x86 python3 也不起作用)

我检查成功 64 bis 版本

python3 -c "import sys;打印(sys.version)"或 python -c "import struct;打印(struct.calcsize('P')*8)";

<块引用>

3.8.7(默认,2020 年 12 月 30 日 02:09:32)[Clang 12.0.0 (clang-1200.0.32.28)]

无论如何,这是否可行,或者谁知道如何使这项工作?

解决方案

Apple M1 是一款 ARM64 架构的处理器,而 TensorFlow 的所有 pip 包都是针对 x86_64 架构编译的.(不包括 raspberry pi 包,但它们无论如何都不会与 MacO 兼容).

如果我们查看 安装页面上的 pip 包名称在 TensorFlow 中,大多数都包含 x86_64amd64,这表明它们是针对 x86_64 架构构建的.

如果您想在 M1 上运行 TensorFlow,您需要:

  • 从以 x86_64 为目标的源代码通过 Rosetta 2 编译 TensorFlow.不幸的是,根据 this issue在 github 上,Rosetta 2 不支持在 TensorFlow 的 pip 构建中启用的 AVX 指令集,因此需要从源代码重建.
  • 使用 Apple 开发的 M1 上对 TensorFlow 的实验性支持,您可以在 此 github 存储库上找到该支持.请注意,如果采用这种方式,某些 Python 软件包可能与 M1 不兼容/不可用.

请注意,截至 2021/01/04,Apple M1 不是TensorFlow 团队支持的架构:

<块引用>

我们目前无法支持 Mac ARM.能够专注于所有 3 个操作系统上的构建问题的开发人员不到一个.

因此,支持必须来自社区.SIG Build 专注于其他几个平台上的构建相关问题,让我们只关注我们官方祝福的 pip 包.

I have macOS Big Sur on a Apple Silicon M1 and I'm unable to install Tensorflow in python3. I removed xcode python3 and installed brew arm64 python3 (x86 python3 doesn't work as well)

I checked successful 64 bis version

python3 -c "import sys; print(sys.version)" or python -c "import struct; print(struct.calcsize('P')*8)"

3.8.7 (default, Dec 30 2020, 02:09:32) [Clang 12.0.0 (clang-1200.0.32.28)]

Can this work anyhow, or who knows, how to make this work ?

解决方案

Apple M1 is a processor with an ARM64 architecture, while all pip packages of TensorFlow are compiled for the x86_64 architecture. (excluding the raspberry pi packages, but they would not be compatible with MacOs anyway).

If we look at the name of the pip packages on the install page of TensorFlow, most of them contains either x86_64 or amd64, that indicates that they are built against the x86_64 architecture.

If you want to run TensorFlow on the M1, you either need to:

  • compile TensorFlow from sources targeting x86_64 through Rosetta 2. Unfortunately, according to this issue on github, Rosetta 2 does not support the AVX instruction set which are enabled in the pip builds of TensorFlow, so rebuilding from source is needed.
  • Use the experimental support for TensorFlow on M1 developed by Apple, that you can find on this github repository. Note that, if going that way, some python packages might not be compatible/available with the M1.

Note that as of 2021/01/04, the Apple M1 is not a supported architecture by the TensorFlow team:

We currently cannot support Mac ARM. There is less than one developer than can focus on build issues on all 3 operating systems.

Hence, support has to come from the the community. There is SIG Build that focuses on build related issues on several other platforms, leaving us to only focus on the pip packages we officially bless.

这篇关于在 Apple 硅 M1 上 python3 安装 Tensorflow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆