Installing Keras 2.8 on a MacBook Laptop

It had been several months since I used a MacOS machine for machine learning with Keras/TensorFlow so I decided to do some examples to make sure there were no significant breaking changes.

I bought a refurbished MacBook Air from the online Best Buy web site. The Mac laptop cost $450 plus tax. The case was a little bit scratched (which I expected) but overall I was satisfied. The paperwork indicated that refurbishing had been done by a company named JemJem.

The Mac machine was running MacOS 10.14 which told me the machine was made in 2018 or 2019.

Note: To use this blog post as an installation guide, lots of details are left out so you must have expert level Mac skills, including a strong working knowledge of using the bash Terminal/shell.

My first step was to install the Anaconda distribution of Python. I went to repo.anaconda.com/archive and used Anaconda version 2020.02 (which contains Python 3.7.6). The installer file is Anaconda3-2020.02-MacOSX-x86_64.pkg. Note: It’s incredibly easy to get the wrong file.


The .pkg file for Anaconda 2020.02 for Mac — very easy to get the wrong file.

I used the .pkg installer file rather than the .sh file. After the installer file downloaded, I went to the Downloads directory and double-clicked on the .pkg file. I accepted all the defaults (location, users, etc.) and there were no problems with the installation. I tested the Anaconda Python install by launching the Terminal program (the bash shell) and then I issued the command “python” and verified I got a “3.7.6” message and the triple greater-than Python prompt. I used the exit() command to stop the interpreter.


The .whl file for TensorFlow/Keras 2.8.0 for Mac — again, very easy to get the wrong file.

Next I installed Keras. I went to pypi.org/project/tensorflow/2.8.0/ | Download Files and downloaded the .whl file for TensorFlow version 2.8.0 for MacOS 10 with Python 3.7 — again, it’s much too easy to get the wrong file. The file is tensorflow-2.8.0-cp37-cp37m-macosx_10_14_x86_64.whl.

After the .whl file downloaded, I opened a Terminal shell and cd’ed to the Downloads directory. I issued the command “pip install (the .whl name)” and crossed my fingers. Installation took about three minutes and looked good. I was happy.

I verified the PyTorch installation by typing the commands:

python

import tensorflow as tf
tf.__version__

from tensorflow import keras as K
K.__version__

and was happy to see that Keras 2.8.0 had been installed.


Verifying Keras has been installed on the Mac laptop.


Note: Installing PyTorch on a Mac machine is almost exactly the same as installing Keras/TensorFlow. I found a .whl file for PyTorch 1.10.0 for Mac with Python 3.7 at download.pytorch.org/whl/torch_stable.html. The file is cpu/torch-1.10.0-cp37-non-macosx_10_9_x86_64.whl. I downloaded the .whl file, opened a Terminal shell, cd’ed to Downloads, and issued the command “pip install (whl file name)”. See jamesmccaffrey.wordpress.com/2022/06/05/installing-pytorch-1-10-0-on-a-macbook-laptop/


Later, I created a demo using the Iris dataset. The code and data can be found at:
jamesmccaffrey.wordpress.com/2022/04/27/the-iris-dataset-example-with-keras-2-8-on-windows-11/.

I copied the PyTorch program I used for Windows. The only change I had to make was to replace the Windows double-backslash characters in the training and test file paths/locations to the Mac single forward-slash characters.


Running the Iris Dataset example with Keras 2.8 on a Mac.

All in all, it was an interesting experiment.



If operating systems were hammers.


This entry was posted in Keras, Miscellaneous. Bookmark the permalink.