在当前虚拟环境下的当前项目路径下
pip install pipreqs
然后输入命令
pipreqs ./
(其他方法:如果遇到编码错误UnicodeDecodeError,则将指定编码为utf8:pipreqs ./ --encoding=utf8或者pipreqs ./ --encoding='iso-8859-1' )
参考依据:(99+ 封私信 / 81 条消息) 如何生成python项目需要的最小requirements.txt文件? - 知乎 (zhihu.com)