Key Takeaways — Chapter 2: Setting Up Your Python Environment

The Four Components You Installed

Component What It Is How You Use It
Python The interpreter that runs your code python script.py
pip The package installer pip install pandas
Virtual environment An isolated Python installation per project python -m venv venv + activate
VS Code Your code editor Write and run code here

The 4-Step Setup Habit

For every new Python project: 1. Create a folder 2. python -m venv venv — create the environment 3. Activate it (Windows: venv\Scripts\activate / macOS: source venv/bin/activate) 4. pip install your packages

Every time you return to a project: 1. Open VS Code in the project folder 2. Confirm the venv is active (look for (venv) in terminal) 3. Code


Command Quick Reference

python --version          # Check Python version
python -m venv venv       # Create virtual environment
source venv/bin/activate  # Activate (macOS/Linux)
venv\Scripts\activate     # Activate (Windows)
deactivate                # Deactivate
pip install package       # Install a package
pip freeze > requirements.txt  # Save package list
pip install -r requirements.txt  # Install from list
python script.py          # Run a script
python                    # Enter REPL
jupyter notebook          # Launch Jupyter

Three Ways to Run Python

Method Best For
REPL (python) Quick tests, one-line calculations, exploration
Script (python file.py) Automation, repeatable tasks, production code
Jupyter Notebook Data exploration, charts, presenting findings

Common Mistakes and Their Fixes

Mistake Fix
"python not recognized" Add Python to PATH (reinstall, check the box)
ImportError: No module named 'pandas' Activate your venv first; then install
Wrong Python version where python (Win) / which python (Mac) to see what's being used
PowerShell script blocked Set-ExecutionPolicy RemoteSigned

The Golden Rule

Always activate your virtual environment before working on a project.

If you see (venv) at the start of your terminal prompt, you're in. If you don't see it, type the activate command.


Next: Chapter 3 teaches you the building blocks of Python — variables, data types, and operators — in the context of real business data.