Przypinanie zależności za pomocą requirements.txt
Zamroź dokładne wersje, aby instalacje były deterministyczne
Przypinanie zależności za pomocą requirements.txt to bezpłatna lekcja MLOps Academy na CoddyKit. To lekcja 1 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej MLOps Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs MLOps Academy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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. 🎯
Często zadawane pytania
Czy lekcja „Przypinanie zależności za pomocą requirements.txt” jest bezpłatna?
Tak — pełny tekst „Przypinanie zależności za pomocą requirements.txt” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu MLOps Academy, przejdź na CoddyKit PRO. Kurs MLOps Academy zawiera 4 lekcji w sumie.
Co nauczysz się w „Przypinanie zależności za pomocą requirements.txt”?
Zamroź dokładne wersje, aby instalacje były deterministyczne Ćwiczysz MLOps Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć MLOps Academy?
Nie wymagamy żadnego doświadczenia. MLOps Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 1 z 4.
Ile czasu zajmuje lekcja „Przypinanie zależności za pomocą requirements.txt”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji MLOps Academy?
Tak. Każda lekcja MLOps Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Przypinanie zależności za pomocą requirements.txt
- Izolowanie projektów za pomocą środowisk wirtualnych
- Ustalanie ziarna losowości dla powtarzalnych uruchomień
- Zapisywanie pełnej konfiguracji uruchomienia