python生成requirements.txt文件

[亡魂溺海] 提交于 2020-08-15 10:31:38

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存在时覆盖。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!