Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
In professional software development, sharing code requires sharing its exact dependencies. Instead of telling teammates or DevOps engineers to manually install multiple individual libraries, Python projects use a standardized manifest file called requirements.txt. This file lists all third-party libraries and version constraints needed to run the application reliably.
pip freezeWhen your virtual environment is active and you have installed all necessary packages, export the complete list of installed packages and their exact versions using pip freeze:
requirements.txt Contents:Each line consists of a package name followed by comparison operators and version numbers.
requirements.txtWhen cloning a project repository on a new machine or deploying to a cloud server (e.g. AWS, Docker, Heroku), initialize a fresh virtual environment and install all dependencies in a single step using the -r flag:
pip reads every line, resolves transitive dependencies, and installs the exact versions specified.
requirements.txt supports flexible version constraint rules defined by PEP 440:
Production containers should not be bloated with testing tools, debuggers, or linters. The standard industry pattern splits requirements into separate files:
requirements.txt (Core Production)requirements-dev.txt (Local Development & CI/CD)To configure a local developer environment:
requirements.txt to Version Control: Always commit requirements.txt to Git so your entire team uses matching dependencies.== for production builds to prevent unexpected breaking changes when libraries publish new releases.pip freeze only inside a clean, project-specific virtual environment—never in your global Python environment, which contains unrelated system packages.pip freeze in Global EnvironmentRunning pip freeze > requirements.txt without an active virtual environment dumps every single package installed on your computer into the project requirements file. Always activate your virtual environment first.
-rRunning pip install requirements.txt attempts to install a single package named literally "requirements.txt". Always include the flag: pip install -r requirements.txt.
Generate a production requirements.txt file from an active virtual environment, and demonstrate how a team member recreates the exact environment in a single command.
requirements.txt file listing all packages installed in the active environment?requirements.txt file?requirements-dev.txt typically reference the base requirements.txt file?django >= 4.0, < 5.0 specify?pip freeze inside a global Python environment discouraged?In the next lesson, we will continue your intermediate Python journey with Project: Package-Ready Mini App (12: Virtual Environments & Pip).
👉 Continue to Next Lesson: Project: Package-Ready Mini App →
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Using pip for Package Management | Project: Package-Ready Mini App |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.