QuickDevGuide

Home › Python

Modules, Packages & Virtual Environments — Python

Modules and packages A module is any .py file; a package is a directory of modules (with an optional init.py). Import with import pkg.module, from pkg import name, or relative imports (from .utils import helper) inside a package. The if name == "main": guard runs code only when a file is executed directly, not when imported. Typical project layout Virtual environments and dependencies Tool Command Create venv python -m venv .venv Activate source .venv/bin/activate (macOS/Linux) · .venv\Scripts\activate (Windows) Install pip install requests Freeze pip freeze > requirements.txt Reproduce pip install -r requirements.txt Modern all-in-one uv init, uv add requests, uv run app.py (or Poetry) Never install project dependencies into the global interpreter — one venv per project.

Key Takeaways