python中导出requirements.txt的几种方法

常见的方法:
1、 pip freezen > requirements.txt
导出结果中可能存在路径
2 pip list –format=freeze >requirement.txt
导出不带路径的

注意:生成requirements.txt,pip freeze会将当前PC环境下所有的安装包都进行生成,再进行安装的时候会全部安装很多没有的包.此方法要注意。

3、 conda 中导出 requirements.txt
方式一、
a.导出
conda list -e > requirements.txt
b.导入安装
conda install –yes –file requirements.txt
方式二、
c.导出 yml 文件方式
conda env export > freeze.yml
d.安装
conda env create -f freeze.yml

4、pipreqs 导出
使用pipreqs,这个工具的好处是可以通过对项目目录的扫描,发现使用了哪些库,生成依赖清单。
step1:安装pipreqs(默认没有安装)
pip install pipreqs
step2:使用pipreqs导出
在python项目的根目录下 使用 pipreqs ./

物联沃分享整理
物联沃-IOTWORD物联网 » python中导出requirements.txt的几种方法

发表评论