在虚拟环境中使用pip生成
$ pip freeze > requirements.txt
会生成所有项目所需的依赖,太多!简直不能忍 。比较适合在env环境中使用这种方法
在指定项目中使用pipreqs生成
强大的pipreqs包,它可以在指定目录下遍历所有python文件下导入的包,并自动生成requirements.txt文件
安装 pip install pipreqs
# 在指定目录下使用:
pipreqs ./
查看requirements.txt文件
cat requirements.txt
如果运行pipreqs ./ 出现以下报错
UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 776: illegal multibyte sequence
可以执行以下命令
pipreqs ./ --encoding=utf8
这样以后安装这个程序就可以用下面的命令一键安装包了
pip install -r requriements.txt