Python项目生成requirements.txt文件之pipreqs的使用

生成requirements.txt时使用pip freeze > requirements.txt会将环境下所有的安装包都进行生成,再进行安装的时候会全部安装很多没有的包.耗时耗力其实是不可取的 .

使用pipreqs,这个工具的好处是可以通过对项目目录的扫描,发现使用了哪些库,生成依赖清单。

安装

pip install pipreqs

使用

在项目的根目录下 使用   pipreqs ./

pipreqs ./ --encoding=utf8

最后

最后生成出来的requirements.txt,可以根据这个文件下载所有依赖

pip install -r requriements.txt
原文地址:https://www.cnblogs.com/fanjp666888/p/11049992.html