Installing PyTorch 1.10.0 on a MacBook Laptop

I most often use Windows OS machines but I sometimes use Mac and Linux machines too. It had been several months since I had used the PyTorch neural network library on a Mac machine so one weekend I figured I’d do a demo.

Just for hoots, I bought a refurbished MacBook Air from the online Best Buy web site. There’s a Best Buy physical store near my house so I figured if I had a problem they could help me out. (I didn’t run into any problems). The Mac laptop cost $450. The case was a little bit scratched and beat up (which I expected) but overall I was satisfied.

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). Note: It’s incredibly easy to get the wrong file. The installer file is Anaconda3-2020.02-MacOSX-x86_64.pkg.


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

I used the .pkg installer file. After the file downloaded, I went to the Downloads directory and double-clicked on the 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 PyTorch 1.10.0 for Mac — again, very easy to get the wrong file.

Next I installed PyTorch. I went to download.pytorch.org/whl/torch_stable.html and downloaded the .whl file for PyTorch version 1.10.0 for MacOS 9 and 10 — again, it’s much too easy to get the wrong file. The file is cpu/torch-1.10.0-cp37-non-macosx_10_9_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 torch as T
T.__version__

and was happy to see that PyTorch 1.10.0 had been installed.


Verifying PyTorch has been installed on the Mac laptop.


Note: Installing TensorFlow/Keras on a Mac machine is almost exactly the same as installing PyTorch. I found a .whl file for TensorFlow/Keras 2.8 for Mac with Python 3.7 at https://pypi.org/project/tensorflow/2.8.0/#files — tensorflow-2.8.0-cp37-cp37m-macosx_10_14_x86_64.whl. I downloaded the .whl file, opened a Terminal shell, cd’ed to Downloads, and issued the command “pip install tensorflow-2.8.0-cp37-cp37m-macosx_10_14_x86_64.whl”.


Later, I created a demo using the Iris dataset. The code and data can be found at:
jamesmccaffrey.wordpress.com/2022/04/20/the-iris-dataset-example-with-pytorch-1-10-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 PyTorch on a Mac.

All in all, it was an interesting way to spend a few hours on a rainy Pacific Northwest weekend.



If operating systems were cars.


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