python生成requirements.txt文件
- 单一虚拟环境下
意思时当前python虚拟环境中下载的所有依赖都会被添加进去,不管项目中是否真实依赖了。
pip freeze > requirements.txt
该命令会在当前项目目录下生成requirements.txt文件
pip install -r requirements.txt
该命令会安装requirements.txt中的依赖
- 使用pipreqs 安装pipreqs
pip 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存在时覆盖。
来源:oschina
链接:https://my.oschina.net/randomobject/blog/4305078