Python 生成項目的 requirements.txt 檔案
1、freeze
說明: 它生成的 requirements.txt 檔案包含目前環境的完全清單,不相關的依賴包也會包含進來,**注意這個庫生成的requirements.txt會包含整個目前環境下的所有庫。**但是呢,如果我們想要的是生成一個項目環境下的庫,是以這個freeze就不太合适了。
安裝:
pip install freeze
使用-生成rrequirements.txt:
#注意先cd到項目所在的目錄下哈
pip freeze > requirements.txt
使用-安裝requirements.txt中的類庫:
pip install -r requirements.txt
2、pipreqs
pipreqs可以通過對項目目錄的掃描,自動發現使用了那些類庫,自動生成依賴清單,隻生成項目相關的依賴到requirements.txt
安裝:
pip install pipreqs
pip的freeze指令隻儲存與安裝在您的環境python所有軟體包。
但有時你隻想将目前項目使用的類庫導出生成為 requirements.txt;
使用方法:pipreqs 加上目前路徑即可。
pipreqs ./path
但是我使用的時候竟然報錯
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIwczX0xiRGZkRGZ0Xy9GbvNGL2EzXlpXazxSP9cnW1Z0RiVnVuFmb1IjYvB3MMBjVtJWd0ckW65UbM5WOHJWa5kHT20ESjBjUIF2X0hXZ0xCMx81dvRWYoNHLrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdssmch1mclRXY39CXldWYtlWPzNXZj9mcw1ycz9WL49zZuBnLwUDO2EjN1kDMyIjNwAjMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
使用網上的方法将encoding該為utf-8沒有卵用
結果——沒有結果,我才浪費時間解決的。——趕緊換其他方法。
https://www.cnblogs.com/jiangchunsheng/p/9317820.html
3、pigar--------推薦使用
安裝:
pip install pigar
使用方法:
輸出資訊比 pipgreqs 詳細
-h, --help show this help message and exit
-v, --version show pigar version information and exit
-u, --update update database, use it when pigar failed you, exit when
action done
-s NAME [NAME ...] search package name by import name, use it if you do not
know import name come from which package, exit when
action done
-c [PATH] check requirements for the latest version. If file path
not given, search *requirements.txt in current
directory, if not found, generate file requirements.txt,
exit when action done
-l LOG_LEVEL show given level log messages, argument can be (ERROR,
WARNING, INFO), case-insensitive
-i DIR [DIR ...] given a list of directory to ignore, relative directory,
*used for* -c and default action
-p SAVE_PATH save requirements in given file path, *used for* default
action
-P PROJECT_PATH project path, which is directory, *used for* default
action
應用:
pigar -c C:\Users\zmj25\PycharmProjects\confusion\classification_eval
是不是非常詳細,哈哈哈