Python pip and requirements.txt¶
pip is the standard package manager used in Python to install and manage external libraries and dependencies^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
External Packages and Dependency Management¶
While Python includes several built-in libraries (such as os, csv, or json) available immediately via import statements, applications often rely on external packages to provide specific functionality^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md]. For example, web frameworks like Flask or database connectors for systems like MySQL and Redis are external packages that must be installed separately^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
The requirements.txt File¶
As an application grows, the list of required external packages expands^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md]. Best practice dictates that dependencies should not be installed individually via command line, but rather defined in a requirements.txt file^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
This file typically lists the package names along with specific version numbers (e.g., Flask == 2.0.2) to ensure consistency across environments^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
Installation Workflow¶
Once a requirements.txt file is created, pip is used to read this file and install the listed libraries in one step^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md]. The standard command to install the dependencies is:
pip install -r requirements.txt
This workflow is often integrated into container builds (e.g., a Dockerfile) to prepare the application environment^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
Related Concepts¶
- [[Flask]]
- [[Docker]]
- [[Python]]
Sources¶
^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md]