Pin Dependencies with requirements.txt
Freeze exact versions so installs are deterministic.
Pin Dependencies with requirements.txt is a free MLOps Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MLOps Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Pin Anything?
Your code calls libraries, and libraries change. Pinning means writing down the exact versions so today's install matches tomorrow's. 📌
The File That Lists Them
In Python, a plain text file named requirements.txt lists every package your project needs, one per line. It is your install recipe.
scikit-learn
pandas
numpyLoose Versions Bite Back
A bare name like pandas installs the newest release, which can differ tomorrow. That silent change is how a working model suddenly breaks.
Pin the Exact Version
Use the == operator to lock a precise version. Now every machine installs the same code, every single time.
scikit-learn==1.4.2
pandas==2.2.1
numpy==1.26.4Freeze What You Have
The pip freeze command prints every installed package with its exact version, ready to paste into your file.
pip freeze > requirements.txtInstall From the File
Hand the file to pip and it recreates your whole setup. The -r flag means read requirements from this file.
pip install -r requirements.txtCompatible-Release Ranges
The ~= operator allows safe patch updates but blocks breaking ones. It accepts 1.4.x but never jumps to 1.5.
scikit-learn~=1.4.0Transitive Dependencies
The packages you list pull in their own dependencies too. Those hidden ones can shift versions and break you just as easily.
Lock the Whole Tree
A lock file records the exact version of every package, including hidden transitive ones. pip-tools and Poetry generate these for you.
pip-compile requirements.inVerify With Hashes
Adding a hash makes pip reject any package whose bytes do not match. It guards against tampered or swapped downloads.
numpy==1.26.4 --hash=sha256:abc123...Commit It to Git
Check requirements.txt into version control beside your code. Now the exact environment travels with every commit and review.
Quick Check
Which line guarantees the same scikit-learn version on every machine?
Recap
You learned to pin exact versions in requirements.txt, freeze and reinstall them, and lock the full tree so installs stay deterministic. 🎯
Frequently asked questions
Is the “Pin Dependencies with requirements.txt” lesson free?
Yes — the full text of “Pin Dependencies with requirements.txt” is free to read here on the web, and the MLOps Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MLOps Academy course, upgrade to CoddyKit PRO.
What will I learn in “Pin Dependencies with requirements.txt”?
Freeze exact versions so installs are deterministic. You practise MLOps Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start MLOps Academy?
No prior experience is required. MLOps Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Pin Dependencies with requirements.txt” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this MLOps Academy lesson?
Yes. Every MLOps Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Pin Dependencies with requirements.txt
- Isolate Projects with Virtual Environments
- Seed Randomness for Repeatable Runs
- Capture the Full Run Config