Setting Up Your ML Environment
1 of 24Python for Machine Learning
Setting Up Your ML Environment
Before writing a single line of machine-learning code you need a reliable, reproducible Python environment. This lesson walks you through every step: choosing a Python distribution, managing packages, and launching your first Jupyter notebook.
1. Installing Python 3.11+
Machine-learning libraries are moving fast. Python 3.11 brought a significant speed-up (10-60 % on many benchmarks), and 3.12 improved error messages. Always install the latest stable release from python.org or use a distribution such as Anaconda / Miniconda.
Verify your installation in a terminal:
# Check Python version
python --version # Should show 3.11.x or higher
# Check pip is available
pip --version
2. Conda vs Pip — Which Package Manager?
Both tools install Python packages, but they solve different problems. The table below highlights the key differences.
| Feature | pip | conda |
|---|---|---|
| Package source | PyPI (Python Package Index) | Anaconda / conda-forge channels |
| Language support | Python only | Python, R, C/C++ libraries, CUDA toolkits |
| Dependency solver | Basic (pip 23+ improved) | SAT solver — resolves entire environment |
| Virtual environments | python -m venv (lightweight) | conda create -n env (heavier, more isolated) |
| Binary packages | Wheels (platform-specific) | Pre-compiled for each OS/arch |
| Speed | Fast installs | Slower solving, but mamba helps |
| Best for | Lightweight projects, CI/CD | Data-science stacks, GPU drivers |
3. Creating a Virtual Environment
A virtual environment isolates your project's dependencies from the system Python and from other projects. Never install ML packages into your base/system Python.
Option A — conda
# Create an environment named "ml-course" with Python 3.11
conda create -n ml-course python=3.11 -y
# Activate it
conda activate ml-course
Option B — venv (built-in)
# Create the environment
python -m venv ml-course-env
# Activate (Linux / macOS)
source ml-course-env/bin/activate
# Activate (Windows PowerShell)
ml-course-env\Scripts\Activate.ps1
4. Installing the Core ML Stack
With your environment activated, install the packages we will use throughout this course:
# Core scientific computing
pip install numpy pandas matplotlib
# Machine learning
pip install scikit-learn
# Jupyter notebooks
pip install jupyterlab notebook
# Optional but handy
pip install seaborn tqdm ipywidgets
5. Verifying Your Installation
Run this quick check script to make sure everything is installed correctly.
import sys
print(f"Python : {sys.version}")
import numpy as np
print(f"NumPy : {np.__version__}")
import pandas as pd
print(f"Pandas : {pd.__version__}")
import matplotlib
print(f"Matplotlib: {matplotlib.__version__}")
import sklearn
print(f"Scikit-learn: {sklearn.__version__}")
print("\n All core packages installed successfully!")
Python : 3.11.7 (main, Dec 8 2023, 14:22:46) NumPy : 1.26.2 Pandas : 2.1.4 Matplotlib: 3.8.2 Scikit-learn: 1.3.2 All core packages installed successfully!
6. Jupyter Notebook Basics
Jupyter notebooks (.ipynb) let you mix code, output,
visualisations, and Markdown text in a single document. They are the
de-facto standard for exploratory ML work.
# Launch JupyterLab (recommended)
jupyter lab
# Or classic notebook
jupyter notebook
Key keyboard shortcuts inside a notebook:
| Shortcut | Action |
|---|---|
| Shift + Enter | Run cell, move to next |
| Ctrl + Enter | Run cell, stay in place |
| Esc then A | Insert cell above |
| Esc then B | Insert cell below |
| Esc then M | Convert cell to Markdown |
| Esc then DD | Delete cell |
7. IDE Recommendations
For writing .py scripts and modules you'll want a good
editor. Here are the top choices for ML work:
| IDE / Editor | Strengths | Free? |
|---|---|---|
| VS Code | Excellent Python extension, integrated terminal, Jupyter support, Git | Yes |
| PyCharm Professional | Advanced refactoring, scientific mode, database tools | Free for students |
| JupyterLab | Best for notebooks, built-in file browser, terminal | Yes |
| Google Colab | Free GPU, zero setup, shareable | Yes (free tier) |
"The best environment is the one you actually use consistently. Pick one, learn its shortcuts, and stick with it."