目录
一、requirements.txt文件的作用
requirements.txt 文件是用于记载项目所需要的运行环境依赖,
即项目依赖包及其对应版本号的信息列表。方便等环境迁移后,通过命令直接安装。
二、如何生成requirements.txt 文件
使用pipreqs第三方库
使用 pipreqs 可以自动检索到当前项目下的所有组件及其版本,并生成 requirements.txt 文件,极大方便了项目迁移和部署的包管理。。
使用步骤:
1、安装pipreqs库
pip install pipreqs
2、在当前目录使用生成
pipreqs ./ --encoding=utf8 --force
- --encoding=utf8 :为使用utf8编码
- --force :强制执行,当 生成目录下的requirements.txt存在时覆盖
- . /: 在哪个文件生成requirements.txt 文件
三、如何使用该文件进行快速迁移
pip install -r requirements.txt