Modules & Packages
pip and Package Management
Installing, managing, and distributing Python packages
Interview: Essential tool — expected knowledge for any Python developer role
pip is the standard package installer for Python. It installs packages from the Python Package Index (PyPI) and manages dependencies. Understanding pip, virtual environments, and requirements files is essential for every Python developer.
Essential pip Commands
- Install:
pip install package— installs latest version from PyPI - Specific version:
pip install package==2.0orpip install "package>=2.0,<3.0" - Upgrade:
pip install --upgrade package - Uninstall:
pip uninstall package - List:
pip list— shows installed packages and versions - Show:
pip show package— detailed info about an installed package
Requirements Files
- Generate:
pip freeze > requirements.txt— lists all installed packages with exact versions - Install from:
pip install -r requirements.txt - Version specifiers: ==, >=, <=, ~=, != — control version constraints
Modern Alternatives
- pipenv: Combines pip and virtualenv with Pipfile.lock for deterministic builds
- poetry: Full dependency management with pyproject.toml, lock files, and publishing
- uv: Extremely fast Rust-based pip replacement — drop-in compatible
- conda: Cross-language package manager popular in data science
Always Use Virtual Environments
Never install packages globally with pip. Always create a virtual environment first: python -m venv .venv && source .venv/bin/activate. This isolates project dependencies and prevents version conflicts between projects.
Use Cases
Setting up project environments with isolated dependencies
Managing team dependencies with requirements.txt or lock files
Publishing packages to PyPI for public or private distribution
Reproducible builds with pinned dependency versions
CI/CD pipeline setup with automated dependency installation
Common Mistakes
Installing packages globally instead of using virtual environments
Using pip freeze without a clean venv — includes unnecessary packages
Not pinning dependency versions — builds break when upstream changes
Forgetting to update pip itself — old pip versions have resolution bugs
Not using pyproject.toml for new projects — it's the modern standard