Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

MacBook M1: installing TensorFlow and Jupyter Notebook | by Gonzalo Ruiz de Villa | gft-engineering | Apr, 2021 | Medium 06/05/2021

21 01:11

!"#$%%&'!()'*+,-"..*+/
01+,%23.%4'"+5'6789-12
:%-1;%%&
!"#$%&"'()*$'+,'-*&&% ."&&"/
012'3'·'4'5*#'2,%+

Last week, I received my new MacBook M1 and I wanted to


setup the local environment to do some machine learning with
TensorFlow. These are the steps that worked for me. I installed
the latest version of TensorFlow available at the time 0.1-
alpha3.

https://medium.com/gft-engineering/macbook-m1-tensorflow-on-jupyter-notebooks-6171e1f48060 Página 1 de 9
MacBook M1: installing TensorFlow and Jupyter Notebook | by Gonzalo Ruiz de Villa | gft-engineering | Apr, 2021 | Medium 06/05/2021 01:11

!"#$%&'%()*"+,,%-./0#
Xcode consists of a suite of tools that developers use to build
apps for Apple platforms.

You can install Xcode from the App Store or you can download
it from the Developer site.

!"#$%1'%()*"+,,%"2#%3/44+)0%56)#%7//,*
8+.9+:#
As defined in the documentation, the Command Line Tools
Package is a small self-contained package available for
download separately from Xcode and that allows you to do
command line development in macOS.

For a fresh install, this command should be enough:

xcode-select --install

https://medium.com/gft-engineering/macbook-m1-tensorflow-on-jupyter-notebooks-6171e1f48060 Página 2 de 9
MacBook M1: installing TensorFlow and Jupyter Notebook | by Gonzalo Ruiz de Villa | gft-engineering | Apr, 2021 | Medium 06/05/2021 01:11

!"#$%;'%()*"+,,%<6)6=/>:#
Anaconda is a distribution of the Python and R programming
languages for scientific computing, that aims to simplify
package management and deployment. However, Anaconda
comes with many Python packages included, some of which are
not Apple Silicon (i.e. ARM) compatible and thus Anaconda is
not ARM compatible. Miniforge has Conda, which means you
can install many of the packages you want such as Pandas,
Scipy, and Numpy — unlike Anaconda, you just have to do the
install manually by running ‘conda install
mypackagenamehere’.

Miniforge homepage: https://github.com/conda-forge/miniforge

I downloaded ‘miniforge3-macosx-arm64.sh’ (v4.10.0 at the


time) from https://github.com/conda-
forge/miniforge/releases/, which is the one for the Apple
Silicon architecture.

And to install it, I used the following command:

bash Miniforge3-MacOSX-arm64.sh

I had to accept licensing and terms and when the installation


was completed I opened a new terminal and run the following
command to verify it worked:

https://medium.com/gft-engineering/macbook-m1-tensorflow-on-jupyter-notebooks-6171e1f48060 Página 3 de 9
MacBook M1: installing TensorFlow and Jupyter Notebook | by Gonzalo Ruiz de Villa | gft-engineering | Apr, 2021 | Medium 06/05/2021 01:11

conda

This is what it shows:

6"#+%'7,25*#%&'")71)7

!"#$%?'%3>#+"#%+%./)0+%#)@6>/)4#)"%+)0
6)*"+,,%7#)*/>=,/A
TensorFlow is a free and open-source software library for
machine learning. It can be used across a range of tasks but has
a particular focus on training and inference of deep neural
networks. Tensorflow is a symbolic math library based on
dataflow and differentiable programming.

To install TensorFlow on Apple Silicon, I followed the


instructions from Apple found in

https://medium.com/gft-engineering/macbook-m1-tensorflow-on-jupyter-notebooks-6171e1f48060 Página 4 de 9
MacBook M1: installing TensorFlow and Jupyter Notebook | by Gonzalo Ruiz de Villa | gft-engineering | Apr, 2021 | Medium 06/05/2021 01:11

https://github.com/apple/tensorflow_macos/issues/153.

First, download environment.yml from


https://raw.githubusercontent.com/mwidjaja1/DSOnMacAR
M/main/environment.yml or use the following content:

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

I created a new conda environment with the following


command:

https://medium.com/gft-engineering/macbook-m1-tensorflow-on-jupyter-notebooks-6171e1f48060 Página 5 de 9
MacBook M1: installing TensorFlow and Jupyter Notebook | by Gonzalo Ruiz de Villa | gft-engineering | Apr, 2021 | Medium 06/05/2021 01:11

conda env create --file=PATH_TO_ENVIRONMENT.YML --


name=YOUR_ENV_NAME

I then activated the newly created environment:

conda activate YOUR_ENV_NAME

And then I installed TensorFlow and TensorFlow Addons for


MacOS v0.1-alpha3:

pip install --upgrade --force --no-dependencies


https://github.com/apple/tensorflow_macos/releases/downlo
ad/v0.1alpha3/tensorflow_macos-0.1a3-cp38-cp38-
macosx_11_0_arm64.whl
https://github.com/apple/tensorflow_macos/releases/downlo
ad/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-
macosx_11_0_arm64.whl

Next, I verified the TensorFlow installation. I ran python and


then imported TensorFlow:

7,25*#%&'")1)7'*51"27*#8'7,#9"2:&"/'*#'1;7<"#

!"#$%B'%6)*"+,,%CD$E"#>%F/"#G//9*
https://medium.com/gft-engineering/macbook-m1-tensorflow-on-jupyter-notebooks-6171e1f48060 Página 6 de 9
MacBook M1: installing TensorFlow and Jupyter Notebook | by Gonzalo Ruiz de Villa | gft-engineering | Apr, 2021 | Medium 06/05/2021 01:11

This one was pretty easy:

conda install notebook -y

And I verified the installation launching the Jupyter Notebook


application:

jupyter notebook

!"#$%H'%6)*"+,,6):%./44/)%+006"6/)+,
$+.9+:#*
The common packages can be installed with conda-forge. For
me, it was the best way to avoid installation problems and
avoid loosing hours googling for the solutions.

Choose the ones you need, for instance:

conda install matplotlib -y


conda install pandas -y
conda install scikit-learn -y

!"#$%I'%*"+>"%$,+E6):%A6"2%"2#%)/"#G//9*
Again:
https://medium.com/gft-engineering/macbook-m1-tensorflow-on-jupyter-notebooks-6171e1f48060 Página 7 de 9
MacBook M1: installing TensorFlow and Jupyter Notebook | by Gonzalo Ruiz de Villa | gft-engineering | Apr, 2021 | Medium 06/05/2021 01:11

jupyter notebook

And tada!

And that’s all!

7>/DG,#*2//"6):
After publishing the article, someone reached me with this
error when installing TensorFlow:

ERROR: tensorflow_macos-0.1a3-cp38-cp38-
macosx_11_0_arm64.whl is not a supported wheel on this
platform.

This happened because Anaconda was installed. As I describe


above, Anaconda is not ARM compatible, so the most direct
way to solve this is to uninstall Anaconda and install Miniforge
instead.

https://medium.com/gft-engineering/macbook-m1-tensorflow-on-jupyter-notebooks-6171e1f48060 Página 8 de 9
MacBook M1: installing TensorFlow and Jupyter Notebook | by Gonzalo Ruiz de Villa | gft-engineering | Apr, 2021 | Medium 06/05/2021 01:11

=> ?,#9"2.&"/ @)1;7,2'A"7,B""C =%6'D9'E 025F4

5#+>)%4/>#J <+9#%<#06D4 !2+>#%E/D>


=,+*)5'*9'%#'"1,#'1&%7:"25 E/D>*J "26)96):J
/<,2,'>3G'5*&&*"#'2,%+,29 ."&&"/'7<,'/2*7,29J P:';")'<%L,'%'97"2;'7"'7,&&J
6"5,'7"':*#+'*#9*8<7:)&'%#+ 1)B&*6%7*"#9J'%#+'7"1*69 C#"/&,+8,'7"'9<%2,J'"2'%
+;#%5*6'7<*#C*#8H'I,2,J 7<%7'5%77,2'7"';")J'%#+ 1,291,67*L,'7"'"::,2'Q
,K1,27'%#+')#+*96"L,2,+ ;")N&&'9,,'7<,5'"#';")2 /,&6"5,'<"5,H'P7N9',%9;
L"*6,9'%&*C,'+*L,'*#7"'7<, <"5,1%8,'%#+'*#';")2 %#+':2,,'7"'1"97';")2
<,%27'":'%#;'7"1*6'%#+'B2*#8 *#B"KH'OK1&"2, 7<*#C*#8'"#'%#;'7"1*6H'R2*7,
#,/'*+,%9'7"'7<,'9)2:%6,H "#'=,+*)5
M,%2#'5"2,

0B")7 I,&1 M,8%&

https://medium.com/gft-engineering/macbook-m1-tensorflow-on-jupyter-notebooks-6171e1f48060 Página 9 de 9

You might also like