00.2 - Setting Up Your Python Development Environment
Development Environment Overview
A Python development environment consists of three components:
┌─────────────────────────────────────────────────────────────┐
│ Python Dev Environment │
│ │
│ ┌──────────────┐ ┌─────────────────┐ ┌─────────────┐ │
│ │ Python 3 │ │ VS Code IDE │ │ Terminal │ │
│ │ Interpreter │ │ + Extensions │ │ (bash/zsh/ │ │
│ │ (CPython) │ │ │ │ PowerShell)│ │
│ └──────────────┘ └─────────────────┘ └─────────────┘ │
│ ▲ ▲ ▲ │
│ └───────────────────┴───────────────────┘ │
│ Your Python Project │
└─────────────────────────────────────────────────────────────┘
Step 1 — Install Python 3
Windows
- Go to https://www.python.org/downloads/
- Download the latest Python 3.x installer
- Important: Check ✅ "Add Python to PATH" before clicking Install
- Click "Install Now"
Verify:
python --version
# Python 3.11.x
pip --version
# pip 23.x from ...
macOS
# Using Homebrew (recommended)
brew install python3
python3 --version
pip3 --version
Linux (Ubuntu/Debian)
sudo apt update
sudo apt install python3 python3-pip python3-venv
python3 --version
Step 2 — Install VS Code
- Download from https://code.visualstudio.com/
- Install the Python extension by Microsoft:
- Open VS Code →
Ctrl+Shift+X(Extensions) - Search "Python" → Install the Microsoft extension
- Open VS Code →
Recommended VS Code Extensions for Python
| Extension | Purpose |
|---|---|
| Python (Microsoft) | IntelliSense, debugging, linting |
| Pylance | Fast type checking and autocompletion |
| Ruff | Ultra-fast linter (replaces flake8) |
| Black Formatter | Auto-format code on save |
| Jupyter | Run notebooks inside VS Code |
| GitLens | Git integration |
Step 3 — Configure VS Code for Python
Press Ctrl+Shift+P and type "Python: Select Interpreter" to choose your Python version.
Add these to your VS Code settings.json (Ctrl+Shift+P → "Open User Settings JSON"):
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"python.analysis.typeCheckingMode": "basic",
"editor.rulers": [88]
}
Step 4 — The Python REPL
The REPL (Read-Eval-Print Loop) is the interactive Python shell — perfect for experimenting.
# Launch the REPL
# In terminal: python3
>>> print("Hello, World!")
Hello, World!
>>> 2 + 3
5
>>> name = "Python"
>>> f"Hello, {name}!"
'Hello, Python!'
>>> exit()
| REPL command | Purpose |
|---|---|
python3 | Start the REPL |
exit() or Ctrl+D | Exit |
_ | Last result (>>> 2+2 then >>> _ gives 4) |
help(str) | Get documentation on any object |
dir(list) | List all methods of an object |
Step 5 — Your First Python Script
Create a file hello.py:
# hello.py — My first Python script
name = input("What is your name? ")
age = int(input("How old are you? "))
print(f"Hello, {name}!")
print(f"In 10 years, you will be {age + 10} years old.")
Run it:
python3 hello.py
# What is your name? Alice
# How old are you? 25
# Hello, Alice!
# In 10 years, you will be 35 years old.
Virtual Environments (Preview)
A virtual environment isolates your project's packages from the global Python installation. You'll learn the full details in Module 06, but here's a quick preview:
# Create a virtual environment
python3 -m venv venv
# Activate it (macOS/Linux)
source venv/bin/activate
# Activate it (Windows)
venv\Scripts\activate
# Install packages (isolated)
pip install requests
# Deactivate
deactivate
Rule: Always use a virtual environment for every project.
Python Code Structure
#!/usr/bin/env python3
"""
Module docstring: brief description of this file.
"""
# 1. Standard library imports
import os
import sys
# 2. Third-party imports
import requests
# 3. Local imports
# from mymodule import myfunction
# 4. Constants
MAX_RETRIES = 3
# 5. Functions and classes
def main():
"""Entry point of the script."""
print("Hello from main!")
# 6. Entry point guard
if __name__ == "__main__":
main()
The if __name__ == "__main__": guard ensures main() only runs when the script is executed directly, not when it's imported as a module.
Key Vocabulary
| Term | Definition |
|---|---|
| Interpreter | The program that reads and executes Python code (python3) |
| REPL | Interactive shell: type Python, get immediate results |
| Script | A .py file containing Python code |
| IDE | Integrated Development Environment (VS Code, PyCharm) |
| Extension | Plugin that adds functionality to VS Code |
| Virtual environment | Isolated Python installation for a single project |
__name__ | Special variable: "__main__" when run directly, module name when imported |
| Shebang | #!/usr/bin/env python3 — tells the OS which interpreter to use |
Summary
- Python 3.10+ is required — always add Python to PATH during installation
- VS Code with the Python + Pylance + Black extensions is the recommended setup
- The REPL (
python3) lets you test code interactively - Use
if __name__ == "__main__":as the entry point in every script - Virtual environments isolate project dependencies — always use them
📄️ 00.1 - Why Python?
Understand Python's origins, what makes it unique, and where it fits in today's technology landscape
📄️ 00.2 - Setup Your Environment
Install Python 3, configure VS Code with extensions, understand the REPL, and create your first script
📄️ Lab - Module 00
Install Python 3, configure VS Code, use the REPL, and write an interactive CLI script
📄️ Quiz - Module 00
30 interactive questions to validate your understanding of Python history, setup, and ecosystem