Python生成requirements.txt方法


Python生成requirements.txt方法

在查看別人的Python項目時,經常會看到一個requirements.txt文件,里面記錄了當前程序的所有依賴包及版本號,其作用是用來在另一個環境上重新構建項目所需要的運行環境依賴。

方法一:

requirements.txt可以通過pip命令自動生成和安裝,這種情況更適用於此項目是單獨的虛擬python環境
生成requirements.txt文件

pip freeze > requirements.txt

安裝requirements.txt依賴

pip install -r requirements.txt

方法二:

使用pipreqs github地址
CTOLib碼庫對這個模塊的描述是:從真實的代碼挖掘出項目真正導入的模塊, 並組織為 pip requirements.txt
安裝

pip install pipreqs

用法

pipreqs /home/project/location

以下摘自github: 
Why not pip freeze?
pip freeze only saves the packages that are installed with pip install in your environment.
pip freeze saves all packages in the environment including those that you don't use in your current project. (if you don't have virtualenv)
and sometimes you just need to create requirements.txt for a new project without installing modules.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM