AIMaks

Setting Up Your ML Environment

30 min readvideoPython Foundations for ML
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:

python
# 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.

Featurepipconda
Package sourcePyPI (Python Package Index)Anaconda / conda-forge channels
Language supportPython onlyPython, R, C/C++ libraries, CUDA toolkits
Dependency solverBasic (pip 23+ improved)SAT solver — resolves entire environment
Virtual environmentspython -m venv (lightweight)conda create -n env (heavier, more isolated)
Binary packagesWheels (platform-specific)Pre-compiled for each OS/arch
SpeedFast installsSlower solving, but mamba helps
Best forLightweight projects, CI/CDData-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

python
# 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)

python
# 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:

python
# 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.

verify_install.py Run
python
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.

python
# Launch JupyterLab (recommended)
jupyter lab

# Or classic notebook
jupyter notebook

Key keyboard shortcuts inside a notebook:

ShortcutAction
Shift + EnterRun cell, move to next
Ctrl + EnterRun cell, stay in place
Esc then AInsert cell above
Esc then BInsert cell below
Esc then MConvert cell to Markdown
Esc then DDDelete 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 / EditorStrengthsFree?
VS CodeExcellent Python extension, integrated terminal, Jupyter support, GitYes
PyCharm ProfessionalAdvanced refactoring, scientific mode, database toolsFree for students
JupyterLabBest for notebooks, built-in file browser, terminalYes
Google ColabFree GPU, zero setup, shareableYes (free tier)
"The best environment is the one you actually use consistently. Pick one, learn its shortcuts, and stick with it."
Up next · Python Refresher: Data Types and Control Flow