使用 pipreqs 生成
通过第三方库
pipreqs
来生成 requirements.txt 文件,这个方式有一个好处,那就是它可以只生成我们当前Python项目中所用到的依赖包及其版本号,而不是像
pip freeze
方式一样把所有包全部列出生成。
安装
pip3 install pipreqs
在当前目录生成
pipreqs . --encoding=utf8 --force
.
表示在当前目录下生成
--encoding=utf8
为使用utf8编码,不然可能会报UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 406: illegal multibyte sequence 的错误。
--force
强制执行,当 生成目录下的requirements.txt存在时覆盖。