Python小技巧

自动生成requirements;

自动生成当前项目的requirements文件

pip freeze > requirements.txt会将环境中的依赖包全都加入,使用pipreqs,在project目录下生成requirements文件即可

1
2
pip install pipreqs
pipreqs . --encoding=utf-8 --force

如果报错是因为没有使用utf-8编码,—encoding=utf8 为使用utf-8编码,不然可能会报错,—force 强制执行,当生成目录下的requirements.txt存在时覆盖。

1
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 186: illegal multibyte sequence