Tools, Workflow, and Git
Set up a productive environment, manage dependencies, and collaborate effectively with Git and GitHub.
Content
Pip and package management
Versions:
Watch & Learn
AI-discovered learning video
Sign in to watch the learning video for this topic.
Pip and Python Package Management — The Practical Guide for CS50 Web
You already set up Python and Node, and you created a virtual environment. Now imagine your project like a burrito: the virtualenv is the tortilla. Pip? Pip is the delivery person bringing beans, salsa, and very specific hot sauce versions. You want the burrito to taste the same every time.
What is pip, and why should you care? (Short answer)
pip is Python's package installer — it downloads and installs libraries (packages) from the Python Package Index (PyPI). In web projects you’ll use pip to add frameworks (Flask, Django), HTTP tools (requests), environment helpers (python-dotenv), and test helpers (pytest).
Why it matters in CS50 Web:
- You learned how to install Python and create a virtual environment. Pip puts the actual tools into that env so your code can import them.
- It helps you reproduce environments between your laptop and a teammate’s machine (or autograder).
Quick commands you’ll actually use (put these in muscle memory)
# activate the virtual environment (you made this already)
source venv/bin/activate # macOS / Linux
venv\Scripts\activate # Windows (PowerShell: venv\Scripts\Activate.ps1)
# upgrade pip itself
python -m pip install --upgrade pip
# install a package (Flask as an example)
pip install Flask==2.0.1
# list installed packages
pip list
# show package info
pip show Flask
# freeze to requirements file for reproducibility
pip freeze > requirements.txt
# install from requirements (on another machine)
pip install -r requirements.txt
# uninstall
pip uninstall Flask
# check for dependency problems
pip check
Note: Using python -m pip ensures you're running pip tied to the right Python interpreter — essential inside venvs.
Reproducibility: requirements.txt and version pinning
The single most important habit: export a requirements.txt and commit it. This is your project's ingredients list.
Example requirements.txt:
Flask==2.0.1
requests==2.28.1
python-dotenv==1.0.0
Why pin versions exactly (==)?
- Two dev machines with the same major package but different minor/patch versions can behave differently.
- Exact pins make debugging and grading reproducible.
Alternative approaches you’ll hear about:
- Using
>=or looser constraints allows updates but can break reproducibility. - Tools like
pip-toolsandpoetryhelp manage transitive dependency pinning more cleanly (explained briefly below).
Dependency hell & the pip resolver (and how to survive)
Dependency hell: when one package wants requests>=2.24 and another wants requests<2.24. Pip’s resolver (improved in 2020) tries to find a set of versions that satisfy all requirements, but conflicts can still occur.
Ways to detect/solve conflicts:
- Run
pip checkafter installs — it reports incompatible installs. - Use
pipdeptree(third-party) to visualize dependency trees. - Pin transitive dependencies manually (or use tools to generate a fully pinned list).
Quote-worthy thought:
"The only true way to avoid dependency hell is predictable builds — lock your dependencies and test your installs regularly."
Tools beyond plain pip (quick comparison)
| Tool | Purpose | When to use it |
|---|---|---|
| pip | Install packages from PyPI | Everyday installs in a venv |
| pipx | Install and run Python CLI apps globally (isolated) | For command-line tools like black or httpie |
| pip-tools | Compile a fully pinned requirements.txt from loose top-level deps | When you want deterministic transitive pins without hand-editing |
| poetry / pipenv | Dependency and project management with pyproject / lockfiles | When you want an all-in-one workflow (optional for CS50) |
Short guidance for CS50: learn pip + requirements.txt first. If you later love workflows, try pip-tools or Poetry — but they’re optional.
Best practices for CS50 web projects
- Always work inside the venv you created earlier. Never install into system Python.
- Upgrade pip at the start of a project:
python -m pip install --upgrade pip. - Install packages with exact versions while developing, then
pip freeze > requirements.txtand commit it. - Keep a
requirements-dev.txtfor test-only packages (pytest, coverage). - Re-create the environment on a new machine with
python -m venv venv && source venv/bin/activate && pip install -r requirements.txt. - Use
pip checkafter installs to catch conflicts early. - If you need a CLI tool globally but isolated from your project, use
pipx install <tool>.
Example workflow (putting everything together)
- Create & activate venv (you did this in the previous lesson).
python -m pip install --upgrade pippip install Flask python-dotenv requestspip freeze > requirements.txtand commit.- On another machine or CI, run
pip install -r requirements.txtandpip check.
Imagine shipping your app to production: the server must install the same requirements.txt so the app behaves like it did on your laptop.
Quick reference cheat-sheet (copy into a README)
- Activate env:
source venv/bin/activate - Install:
pip install <pkg> - Freeze:
pip freeze > requirements.txt - Install from freeze:
pip install -r requirements.txt - Info:
pip show <pkg> - Debug deps:
pip check
Final takeaways
- Pip is the standard tool to install Python packages — pair it with the virtual environment you already set up.
- Always export and commit
requirements.txtfor reproducible CS50 projects. - Use
python -m pipto make sure pip talks to the correct Python. - Learn the simple workflow now; explore pip-tools, pipx, or Poetry later if you want fancier dependency management.
"Treat your requirements.txt like a time capsule: it preserves the exact state your code expects. Open it later, and your code won't haunt you with mysterious errors."
Happy pip-installing. Next up: we'll connect these libraries to your web app — routing, templates, and that first dynamic page that makes your classmates gasp with envy.
Comments (0)
Please sign in to leave a comment.
No comments yet. Be the first to comment!