Setting Up a Machine Learning Environment on Mac, Windows, and Ubuntu
- Debapriya Mukherjee
- Dec 4, 2024
- 3 min read

Machine learning requires a robust environment equipped with the necessary tools and frameworks for seamless development. Setting up such an environment depends on your operating system. This guide provides detailed steps for Mac, Windows, and Ubuntu.
1. Setting Up a Machine Learning Environment on macOS
Prerequisites
Operating System: macOS 10.15 or later.
Hardware Requirements: At least 8GB of RAM, though 16GB+ is preferred for large models.
Tools: Python, Homebrew, IDE (e.g., VS Code or PyCharm), and GPU drivers (if applicable, for M1/M2 Macs).
Steps
1.1 Install Homebrew
Homebrew is a package manager for macOS.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Verify installation:
brew --version
1.2 Install Python and Dependencies
Install Python using Homebrew:
brew install python
Verify Python version:
python3 --version
Install pip and virtualenv:
python3 -m pip install --upgrade pip
python3 -m pip install virtualenv
1.3 Set Up a Virtual Environment
Create a virtual environment:
python3 -m virtualenv ml_env
Activate the environment:
source ml_env/bin/activate
1.4 Install Machine Learning Libraries
Install essential libraries:
pip install numpy pandas scikit-learn matplotlib tensorflow keras pytorch
Install Jupyter Notebook:
pip install notebook
Start Jupyter:
jupyter notebook
1.5 Configure IDE
Install VS Code: brew install --cask visual-studio-code
Install Python extensions from the VS Code marketplace.
2. Setting Up a Machine Learning Environment on Windows
Prerequisites
Operating System: Windows 10 or later.
Hardware Requirements: At least 8GB of RAM, GPU support (CUDA-capable NVIDIA GPUs for accelerated computing).
Tools: Python, Anaconda/Miniconda, Visual Studio Code or PyCharm, and GPU drivers (if applicable).
Steps
2.1 Install Python
Download Python from python.org.
During installation, enable "Add Python to PATH."
Verify installation: python --version
2.2 Install Anaconda or Miniconda
Create a Conda environment:
conda create --name ml_env python=3.9
Activate the environment:
conda activate ml_env
2.3 Install Machine Learning Libraries
Using Conda:
conda install numpy pandas scikit-learn matplotlib
For TensorFlow or PyTorch:
conda install -c conda-forge tensorflow pytorch torchvision torchaudio
Install Jupyter Notebook:
conda install jupyter
2.4 Install GPU Drivers
If you have a CUDA-capable NVIDIA GPU:
Install NVIDIA GPU drivers from the NVIDIA website.
Install CUDA Toolkit and cuDNN libraries compatible with your GPU.
2.5 Configure IDE
Download VS Code or PyCharm.
Install Python extensions or JetBrains plugins for Python.
3. Setting Up a Machine Learning Environment on Ubuntu
Prerequisites
Operating System: Ubuntu 20.04 or later.
Hardware Requirements: At least 8GB of RAM, GPU support (optional but recommended).
Tools: Python, pip, virtualenv, Jupyter Notebook, and GPU drivers (if applicable).
Steps
3.1 Update System Packages
sudo apt update && sudo apt upgrade -y
3.2 Install Python
Install Python:
sudo apt install python3 python3-pip
Verify installation:
python3 --version
3.3 Set Up a Virtual Environment
Install virtualenv:
pip3 install virtualenv
Create and activate a virtual environment:
virtualenv ml_env
source ml_env/bin/activate
3.4 Install Machine Learning Libraries
Install essential libraries:
pip install numpy pandas scikit-learn matplotlib tensorflow keras pytorch
Install Jupyter Notebook:
pip install notebook
Start Jupyter:
jupyter notebook
3.5 Install GPU Drivers (Optional)
Check GPU: lspci | grep -i nvidia
Install NVIDIA GPU drivers: sudo apt install nvidia-driver-470
Install CUDA Toolkit and cuDNN compatible with your system.
3.6 Configure IDE
Install VS Code: sudo snap install --classic code
Install Python extensions from the marketplace.
Final Notes
Environment Management: Use virtualenv or conda to isolate your projects.
Hardware Acceleration: Use GPUs for intensive tasks; configure TensorFlow or PyTorch to utilize GPU resources.
Backup Configurations: Export your environment settings for replication: pip freeze > requirements.txt
Each operating system offers unique advantages, and your choice should depend on your familiarity and specific requirements. Following these steps ensures a robust machine-learning setup tailored to your development needs.
Comments