0Pricing
MLOps Academy · บทเรียน

ตรึง Dependencies ด้วย requirements.txt

ล็อกเวอร์ชันที่แน่นอนเพื่อให้การติดตั้งได้ผลเหมือนเดิมทุกครั้ง

ตรึง Dependencies ด้วย requirements.txt เป็นบทเรียน MLOps Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน MLOps Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส MLOps Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

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
numpy

Loose 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.4

Freeze What You Have

The pip freeze command prints every installed package with its exact version, ready to paste into your file.

pip freeze > requirements.txt

Install 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.txt

Compatible-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.0

Transitive 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.in

Verify 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. 🎯

คำถามที่พบบ่อย

บทเรียน “ตรึง Dependencies ด้วย requirements.txt” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ตรึง Dependencies ด้วย requirements.txt” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส MLOps Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส MLOps Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ตรึง Dependencies ด้วย requirements.txt”

ล็อกเวอร์ชันที่แน่นอนเพื่อให้การติดตั้งได้ผลเหมือนเดิมทุกครั้ง คุณปฏิบัติ MLOps Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน MLOps Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน MLOps Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “ตรึง Dependencies ด้วย requirements.txt” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน MLOps Academy นี้ได้ไหม

ได้ บทเรียน MLOps Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ตรึง Dependencies ด้วย requirements.txt
  2. แยกโปรเจกต์ด้วยสภาพแวดล้อมเสมือน
  3. กำหนดค่าเมล็ดสุ่มเพื่อให้รันซ้ำได้ผลเดิม
  4. บันทึกการตั้งค่าการรันทั้งหมด
← กลับไปที่ MLOps Academy