- 1 min

Automatically generate requirements.txt and use it to install packages

Table of Contents

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.

pip freeze > requirements.txt

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.

 // Install pipreqs
 pip install pipreqs

 // Generate requirements.txt
 pipreqs ./

Use requirements.txt to install packages

 pip install -r requirements.txt
Topaz

Topaz

Always keep learning.

comments powered by Disqus
rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium vimeo