简体   繁体   English

M1 Mac Tensorflow VS Code Rosetta2

[英]M1 Mac Tensorflow VS Code Rosetta2

I'm struggling to install tensorflow with a M1 mac.我正在努力使用 M1 mac 安装 tensorflow。 I've got python 3.9.7 and Monterrey 12.3 and apple silicon visual studio code.我有 python 3.9.7 和 Monterrey 12.3 以及 Apple Silicon Visual Studio 代码。 There is an apple solution involving miniconda apple dependancies and tensorflow-macos and tensorflow-metal.有一个苹果解决方案涉及 miniconda apple dependencies 和 tensorflow-macos 和 tensorflow-metal。 However this solution is not good for me as I have to use Rosetta2 emulator for multiple packages including PyQt5 etc. I was wondering if anyone has been able to use their M1 macs and pip installed tensorflow in a venv rosetta terminal.然而,这个解决方案对我来说并不好,因为我必须将 Rosetta2 模拟器用于多个包,包括 PyQt5 等。我想知道是否有人能够使用他们的 M1 mac 和 pip 在 venv rosetta 终端中安装 tensorflow。 Thank you.谢谢你。

Kevin凯文

Running TensorFlow on miniforge + conda-forge (arm64)在 miniforge + conda-forge (arm64) 上运行 TensorFlow

TensorFlow can run natively on M1 (arm64) macs. TensorFlow 可以在 M1 (arm64) mac 上原生运行。 A highly recommended, easy way to install TensorFlow on arm64 macs is to via conda-forge .强烈推荐在 arm64 mac 上安装 TensorFlow 的简单方法是通过 conda- forge 。 You should install python via miniforge or miniconda , because there is an arm64 (Apple Sillicon) distribution.您应该通过miniforgeminiconda安装 python ,因为有一个 arm64 (Apple Sillicon) 发行版。 With this, as of today, you can install the latest version 2.10.0 of TensorFlow:有了这个,从今天开始,您可以安装 TensorFlow 的最新版本 2.10.0:

$ lipo -archs $(which python3)   # python3 is running natively as arm64
arm64
$ conda install -c conda-forge tensorflow 

Note: tensorflow-macos 2.4.0 is obsolete so you shouldn't be using that.注意: tensorflow-macos 2.4.0 已过时,因此您不应该使用它。

But still want Rosetta 2?但还是想要 Rosetta 2? Try conda-forge.试试康达锻造。

If you really need to have python running on Rosetta 2 (x86_64) in cases where some packages does not support arm64 , you can still install TensorFlow with a macOS x86_64 release via conda.如果您确实需要在 Rosetta 2 (x86_64) 上运行 python,在某些软件包不支持 arm64的情况下,您仍然可以通过 conda 安装带有 macOS x86_64 版本的 TensorFlow。 Installing via pip and PyPI repository won't work here, because you will run into Illegal hardware instruction segfault because Google's official TF macos-x86_64 wheel releases on PyPI assumes a target platform that has AVX instructions.通过pip和 PyPI 存储库安装在这里不起作用,因为您将遇到Illegal hardware instruction段错误,因为 PyPI 上的 Google 官方 TF macos-x86_64 wheel 版本假设目标平台具有 AVX 指令。

$ lipo -archs $(which python3)   # x86_64 means Rosetta 2
x86_64
$ conda install -c conda-forge tensorflow       # install via conda
$ python -c 'import tensorflow; print(tensorflow.__version__)'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM