How I set my M2 Macbook Pro for Machine Learning
Table of contents
This post will let you set up a machine-learning environment on your new macbook pro M2.
Homebrew
It is very important to get this package manager installed on your macbook.
It installs, updates, and deletes all the packages that you need.
To install it, open the terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
After installation, you need to add it to the path to be able to use the 'brew' command.
Once homebrew is properly installed on the machine, you will now be able to start using brew to install and delete packages.
To install, use brew install 'name'
To upgrade, use brew upgrade 'name'
To uninstall, use brew uninstall 'name'
We'll now use brew to install some packages
Docker: brew install docker
Git: brew install git
VSCode: brew install --cask visual-studio-code
Miniforge3
Download Miniforge3 for macOS - arm64 chips.
To install miniforge3 to the path, open the terminal and run the following:
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
TensorFlow
Restart the terminal and we will create an environment to set up TensorFlow.
conda create --n TensorFlow python=3.8
To activate the created environment,
conda activate TensorFlow
We will now install TensorFlow Dependencies from apple conda channel:
conda install -c apple tensorflow-deps
Installing base tensorflow:
python -m pip install tensorflow-macos
Tensorflow metal:
python -m pip install tensorflow-metal
PyTorch
Create and activate a new environment for PyTorch:
conda create --n Pytorch python=3.8
conda activate Pytorch
Installing the latest version of PyTorch:
pip3 install torch torchvision torchaudio
Other Packages
Installing other common packages on your environment:
conda install jupyter pandas numpy matplotlib scikit-learn seaborn tqdm
To start jupyter notebook in your environment,
jupyter notebook
Import all the libraries to check if they are properly installed:
import numpy as np
import pandas as pd
import torch
import sklearn
import tensorflow as tf
import seaborn as sns
import matplotlib.pyplot as plt
Yayy! Your new MacBook is now capable of running TensorFlow, PyTorch and other machine-learning libraries.