安裝pipreqs
pip install pipreqs
執(zhí)行
pipreqs --use-local
報(bào)錯(cuò):UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 2: illegal multibyte sequence
需要上--encoding=utf8 如下
pipreqs --use-local --encoding=utf8 --force .
python 自動(dòng)生成當(dāng)前項(xiàng)目的requirements文件
有幾種辦法:
1、使用pip freeze
pip freeze > requirements.txt
這種方式是把整個(gè)環(huán)境中的包都列出來了,如果是虛擬環(huán)境可以使用。
通常情況下我們只需要導(dǎo)出當(dāng)前項(xiàng)目的requirements.txt,這時(shí)候就推薦pipreqs了
2、使用 pipreqs
可以通過對(duì)項(xiàng)目目錄的掃描,自動(dòng)發(fā)現(xiàn)使用了那些類庫,把項(xiàng)目相關(guān)的依賴到requirements.txt自動(dòng)生成依賴清單,