As your Python projects grow, it becomes essential to manage package installations efficiently. Thankfully, we can use requirements.txt
file and the pip package manager to install Python packages. It simplifies the process of managing dependencies by providing a centralized list of packages and their versions. This ensures that all team members working on a project have the same packages installed, promoting consistency and eliminating compatibility issues. Additionally, using a requirements.txt
file enables easy reproducibility, allowing you to recreate the exact environment in which your project was developed. This tutorial explains how to install Python packages using requirements.txt
file and pip.
Firstly, create a plain text file named requirements.txt
in the root directory of your project. This file will contain a list of all the packages and their specific versions that your project depends on. Each package should be listed on a separate line. For example:
torch>=2.0.0
torchvision>=0.15.0
opencv-python>=4.7.0
Navigate to the project's directory and run the following command to install all the packages listed in the requirements.txt
file:
pip install -r requirements.txt
pip3 install -r requirements.txt
The pip will automatically resolve and handle any dependencies, ensuring a smooth installation process.
Leave a Comment
Cancel reply