pipreqs模块
github:https://github.com/bndr/pipreqs
适用于 当前使用全局环境,如果使用 freeze命令会将所有依赖都加入到txt中。而使用 pipreqs 方法则只收入当前项目使用模块。
安装:
pip install pipreqs
进入项目根目录生成txt文件
pipreqs . --encoding=utf8 --force
注意 --encoding=utf8 为使用utf8编码,不然可能会报UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 406: illegal multibyte sequence 的错误。
--force 强制执行,当 生成目录下的requirements.txt存在时覆盖。
单虚拟环境的情况
pip freeze > requirements.txt
安装requirements.txt
pip install -r requirements.txt