I'm struggling to install tensorflow with a M1 mac. I've got python 3.9.7 and Monterrey 12.3 and apple silicon visual studio code. There is an apple solution involving miniconda apple dependancies and tensorflow-macos and 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. Thank you.
Kevin
TensorFlow can run natively on M1 (arm64) macs. A highly recommended, easy way to install TensorFlow on arm64 macs is to via conda-forge. You should install python via miniforge or miniconda, because there is an arm64 (Apple Sillicon) distribution. With this, as of today, you can install the latest version 2.10.0 of TensorFlow:
$ 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.
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. 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.
$ 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__)'