Automatically generate requirements.txt and use it to install packages
Table of Contents
- Introduction
- Method 1: Use pip to generate requirements.txt
- Method 2: pipreqs tool to generate requirements.txt
- Use requirements.txt to install packages
Introduction
The requirements.txt record all the dependent packages of the current program and their version and is used to rebuild the operating environment dependencies required for the project on another PC.
Method 1:Use pip to generate requirements.txt
This method needs to cooperate with Virtualenv, otherwise the packages in the entire environment will be listed.
Method 2: pipreqs tool to generate requirements.txt
The advantage of this tool is that it can automatically discover which class libraries are used by scanning the project directory, and automatically generate a dependency list. The disadvantage is that there may be some deviations, which need to be checked and adjusted by yourself.