Setup Mac for Machine Learning with TensorFlow in 13 minutes (works for all M1, M2)

In this fast‑paced, hands‑on tutorial Daniel Bourke walks viewers through preparing an Apple‑silicon Mac (M1, M1 Pro, or M1 Max) for machine‑learning development with TensorFlow. He begins by installing Homebrew, then downloads and installs Miniforge 3 (a Conda distribution for ARM64). After restarting the terminal, he creates a project directory and a local Conda environment inside it. Using the Apple Conda channel, he installs the required TensorFlow dependencies, then installs the Apple‑optimized tensorflow‑macos package followed by the TensorFlow‑Metal plugin to enable GPU acceleration via Apple’s Metal framework. He also adds common data‑science libraries (Jupyter, Pandas, NumPy, Matplotlib, scikit‑learn) and optionally TensorFlow Datasets. Finally, he launches a Jupyter notebook to import the libraries and runs a short script that prints TensorFlow’s version and confirms that both the CPU and the M1 GPU are visible to TensorFlow, demonstrating successful GPU‑accelerated setup. Throughout, he points to a GitHub repo and description links for deeper explanations and invites viewers to ask questions in the comments.
Chapters
Oh, hello there and welcome to the M1 machine learning cooking show. I mean, recently you might have picked up one of these new bad boys. This is a 14-inch MacBook Pro. You can tell with the MagSafe, it's one of the new ones with the M1 Pro chip. I'm not going to go over what it is. It's a beautiful machine. It's brand new. Uh, I can show you that it's an M1 Pro here. There's M1 Max. The code in this video will work for the M1, M1 Pro, and M1 Max. At least it should. From my tests, we're going to go ahead and set up an environment or get our machines ready for machine learning, specifically using some data science, the common data science packages like Pandas, NumPy, Matplotlib, scikit-learn, and Jupyter, and TensorFlow. And even more importantly, running TensorFlow on the GPU that's inside the M1, M1 Pro, and M1 Max. So without any further ado, let's get into it. I'm going to jump in. If you want any of the links, by the way, they'll be in the description below. This is on my GitHub. This is just some code that I use to set up an environment to do a speed test of all these new machines. So I'm going to open up Terminal. I'm going to zoom in here. Let's go over there. So this is going to be a relatively fast-paced tutorial. If you'd like an explanation of anything that I'm doing, uh, please refer to the links below. There'll be a longer text-based explanation and you can see the stuff there. So let's jump in. So the first thing that we're going to do is get Homebrew. From brew.sh. Now there's a beautiful one-liner of a code here. Homebrew is a package manager that should really come installed on Macs and Apple laptops, but it, it doesn't. It helps you install other software. So when you copy this code into here, you're going to have to enter your password. I've just entered mine. It doesn't show up because it hides it automatically. We'll press enter. It's going to install a whole bunch of different stuff here. I'll press Enter again. It might take a few minutes depending on your internet connection, and so I'm going to speed this up until it gets to the next step, and then we'll go over that together. Beautiful! That took a couple of minutes on my machine. Your experience may vary. Now, Homebrew tells us a whole bunch of things that it did. You can go back and read those if you like. As you can see here, installation successful. But now it says to run these two commands in your terminal to add Homebrew to your PATH. This will just allow you to use the brew command, such as like here. Now, I will put a little caveat here. That is, there are ways to do this without installing Homebrew, but just take it from me that you should install Homebrew because you're going to eventually end up using it. It has a bunch of useful stuff for you. Now let's go back to Instructions. We're going to now download MiniForge 3, which is a Conda installer. If you'd like to learn more on that, there's links in the resources, but this link is going to directly download an.sh file to our machine. We see there MiniForge 3 macOS X ARM64. Basically, Homebrew and MiniForge are package managers, and package managers help us install other software to our machine. So once we've downloaded that I've got it saved to Downloads there. You can also see it down here. We're going to run these 3 commands here. This is step 3, install Miniforge 3 into home directory. chmod changes the permissions on the file to make it executable. That's what the x is. sh is just basically saying, hey, run this shell program. And then source Miniforge 3/bin/activate is going to activate the environment if it gets installed successfully. I'm going to run all 3 of these. Press Enter, follow the prompts. You have to read this, you have to go right down to the bottom, and once you get down to the bottom, you can press Yes. So let's just get there. This is basically saying you agree to all of the license terms. Where do you want to install it? I'm just going to install it in my home directory under Daniel Bourke. Press Enter. It's going to install a whole bunch of stuff. It's going to enable us to use Conda. That's the most important thing. We get Python 3.9.7. Do we wish to initialize Conda? Yes. Beautiful. Thank you for installing Miniforge 3. Now we're going to clear this again, and to make sure the changes take effect, we're going to restart terminal. You might also notice that there's now base here in front of our Command Prompt. That's just to say that the Conda prompt is available now, but sometimes it messes up. So I'm going to restart Terminal just to quit it and open it up. Terminal— there we go. Just zoom in so you can see. Take that to the side. Now I'm going to create a directory to test a TensorFlow environment. I'm going to call it tensorflow_test using the mkdir function, and then I'm going to change into that. You can call this directory anything. So if you're working on a project, say, TensorFlow Computer Vision, you might make a directory called TensorFlow Computer Vision. You can really call this whatever you want. So mkdir tensorflow_test, change in that directory. Beautiful. Now you see we've got tensorflow_test here. ls, there's nothing in there. We're still in the base environment. Beautiful. Now it's time to make a Conda environment. An environment, I think of it as like a room in your house. Uh, so you can imagine in the kitchen you've got all the tools to cook stuff, and it'd be weird to have an oven in, say, your bedroom. You might have an oven in your bedroom, I don't know. But it's the same on your machine. You create an environment. In this case, we're using Conda. Other, other tools to do it are Virtualenv and whatnot, but we're using Conda to create an environment so that we can work on different projects within that environment and have access to the tools that we need. So they're not getting mixed up in different rooms on our computer or different files on our computer. It's going to copy this, conda create prefix environment. The dot here means that it's going to create an environment in the file path, everything before /env. So it means create an environment that lives in everything before env And then we're going to activate that env. I'll show you what that looks like. Beautiful. Environment location. So see what I mean? Because I put the dot there, it meant that I didn't have to type all of this. So now my environment, env, I called it env, is going to live within the TensorFlow test folder. So I'm going to say proceed. Thank you. And now to activate the environment, you can type in the long version of conda activate the file path /Users/Daniel/TensorFlow/test/env, or in my case, or in our case, we just ran conda activate./env, which means, hey, the current directory /env. Now if we go ls, we've got the env folder there. I'm going to clear all this so we've got some room. Now We can get into the fun part. We've got an environment ready to go. We've got a room ready on our computer that we can install different software. Let's now install Apple's TensorFlow dependencies. So Apple have made it really accessible to start using TensorFlow on new M1 machines. So they've created a Conda channel called apple. This is what this command stands for: conda install from channel apple TensorFlow dependencies. Now TensorFlow is quite a large piece of software, which is why it comes with lots of dependencies. So let's run that. It's going to take a few minutes depending on your internet connection, and you'll see a whole bunch of things come up here in a second that is just going to install a lot of different software within our current environment. We're going to say yes, please install all of that. The osx-arm64 stands for ARM64 is the software, or the hardware architecture that the M1 chip is built on. And this is going through nice and quick. I've got some good internet where I am at the moment. So we see Keras preprocessing, there's a package being installed there, a few more other things. There's TensorBoard. Wonderful. So I'm going to clear that again, make the screen a little bit more clear. Now we can install base TensorFlow. So that's with this command here. I'm going to run that and talk about it. So python -m pip install tensorflow-macos. TensorFlow-macos is Apple's fork of base TensorFlow, so it's the exact same as what you'd find on tensorflow.org. tensorflow.org— wrong website— tensorflow.org, except it's been optimized for Apple hardware. Oh, beautiful, that installed nice and click— quick. Let's go back to the GitHub, and then we can now install TensorFlow Metal. Now this is one of the most important points. It's going to install quite quick. Beautiful. Look how quick that was. TensorFlow Metal is going to enable GPU acceleration on M1, M1 Pro, and M1 Max. Why is it called TensorFlow Metal? Well, if we look up Apple Metal— Metal is Apple's GPU framework. Yeah, accelerating graphics and much more. So if you're using a Mac, which if you're watching this video you probably are, it uses Metal to accelerate graphics. And if we go Apple TensorFlow Metal, Apple have developed a TensorFlow Metal plugin, which is a pluggable device in TensorFlow to enable— there we go— accelerate training with Metal on Mac GPUs. Long story short, if you only install TensorFlow macOS, which is what we did here, you can still use TensorFlow. It just won't leverage the GPU that's on your new M1 device. So that's why if you want to use GPU computing, we install TensorFlow Metal. So now let's get rid of that. Finally, if you want to install TensorFlow Datasets and run the benchmarks that are included in the repo, I'm going to have another video that's going over the M1 machine learning test. You can install TensorFlow Datasets. I might just do that because it's nice and quick. That'll give you access to a whole bunch of different datasets packaged within TensorFlow. So we'll clear that, and then if you want to install some, uh, standard common data science packages, you can run conda install. This is going to install Jupyter for Jupyter Notebooks, Pandas, NumPy, Matplotlib, and scikit-learn. I use these almost every day. I'm going to go yes, please install all of that. Fair few packages here, so I'm going to speed this up as well. Beautiful. Now that's all done. I'm going to clear the screen, make it more visible, and then to test it, we can start out a Jupyter Notebook. That's going to open up a Jupyter Notebook in my browser. Wonderful. If everything worked, you should get something like this. I'm going to start a new notebook, and I'm going to copy this command here. Bring that into the notebook. Just going to maximize that, zoom in so you can see. And so this is going to import NumPy, Pandas, scikit-learn, TensorFlow, STF, and Matplotlib. And it's also going to check whether TensorFlow has GPU access or not and the current version of TensorFlow. So let's run that. It may take a little while if you're importing things for the first time. So once again, I'm going to speed this up and I'll come back when it's got the output. Beautiful! Look at that. Now that took about a minute, maybe 2 minutes on my machine. So it says here that TensorFlow now has access to the physical device, it has access to the CPU, and it also has access to the GPU. Which if we have a look at here, system information, we have on the M1 Pro, we have a 14-core GPU. Wonderful. So that just means that— oh, there's Metal. Metal GPU family, Apple. So that just means if we run TensorFlow code now, not only will it be able to leverage the CPU, it will also be accelerated on the GPU. So with all that being said, happy machine learning. Oh, typo. And if you have any questions, leave them in the comments below. And if you have any further resource needs, check out the links below. It's got all the information there.
More from Daniel

Small Language Models (SLMs) Are the Future: Fine-Tuning AI That Runs on Your iPhone

Introducing Sunny - A MedGemma-Powered Skin Health Tracking App (Kaggle Competition Entry)

Benchmarking: NVIDIA DGX Spark & NVIDIA RTX 4090 | Part 4 - Comparing the results

Benchmarking: NVIDIA DGX Spark & NVIDIA RTX 4090 | Part 3 - Running LLMs on the RTX 4090

Benchmarking: NVIDIA DGX Spark & NVIDIA RTX 4090 | Part 2 - Formalizing the tests

Benchmarking: NVIDIA DGX Spark & NVIDIA RTX 4090 | Part 1 - Creating a series of tests

Local Multimodal RAG on the NVIDIA DGX Spark | Part 4 - Publishing our demo to Hugging Face

Local Multimodal RAG on the NVIDIA DGX Spark | Part 3 - Putting it all together


