python項目下生成requirements.txt方法
一、使用pip freeae
pip freeze > requirements.txt
該命令存在局限:
該命令只會生成通過pip install 安裝的包
如果沒有創(chuàng)建Python的虛擬環(huán)境virtualenv,該命令會將環(huán)境中所有的包都輸出到requirements.txt文件,不管你當前的Project有沒有用到這些包
二、使用pipreqs
Pipreqs 只會統(tǒng)計項目使用的包
2.1、安裝pipreqs
pip install pipreqs
2.2、使用方法
pipreqs "目錄" #在目錄下生成requirements.txt
2.3、特殊說明
2.3.1、Mac 下沒法使用
pipreqs zsh: command not found: pipreqs
沒有找到使用辦法
2.3.2、Linux 使用報錯
pipreqs ./
Traceback (most recent call last):
File "/usr/bin/pipreqs", line 7, in <module>
from pipreqs.pipreqs import main
File "/usr/lib/python2.7/site-packages/pipreqs/pipreqs.py", line 51, in <module>
from pipreqs import __version__
ImportError: cannot import name __version__解決辦法,更換pipreqs版本
# 查看可安裝版本
pip install pipreqs==100
You are using pip version 7.1.0, however version 22.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting pipreqs==100
Could not find a version that satisfies the requirement pipreqs==100 (from versions: 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.2.5, 0.2.7, 0.2.8, 0.2.9, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.3.4, 0.3.5, 0.3.6, 0.3.7, 0.3.8, 0.3.9, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.4.4, 0.4.5, 0.4.6, 0.4.7, 0.4.8, 0.4.9, 0.4.10, 0.4.11)
No matching distribution found for pipreqs==100
# 選擇某一版本安裝
pip install pipreqs==0.4.0
# 查看能否使用
pipreqs --help
pipreqs - Generate pip requirements.txt file based on imports
Usage:
pipreqs [options] <path>
Options:
--use-local Use ONLY local package info instead of querying PyPI
--pypi-server Use custom PyPi server
--proxy Use Proxy, parameter will be passed to requests library. You can also just set the
environments parameter in your terminal:
$ export HTTP_PROXY="http://10.10.1.10:3128"
$ export HTTPS_PROXY="https://10.10.1.10:1080"
--debug Print debug information
--encoding <charset> Use encoding parameter for file open
--savepath <file> Save the list of requirements in the given file
--force Overwrite existing requirements.txt2.3.3、Windows下使用
pipreqs "目錄" --encoding=utf8
三、更換環(huán)境后安裝requirements.txt
pip install -r requirements.txt
到此這篇關(guān)于python項目下生成requirements.txt方法的文章就介紹到這了,更多相關(guān)python requirements.txt內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- python生成requirements.txt的兩種方法
- 詳解python中requirements.txt的一切
- python?中的requirements.txt?文件的使用詳情
- python導(dǎo)出requirements.txt的幾種方法總結(jié)
- python生成requirements.txt文件的兩種方法
- Python pip通過requirements.txt 文件安裝依賴
- Python如何生成requirements.txt
- Python?requirements.txt的具體使用
- python生成requirements.txt文件的推薦方法
- python項目中requirements.txt的用法實例教程
- Python requirements.txt使用小結(jié)
相關(guān)文章
Python?Pandas數(shù)據(jù)合并pd.merge用法詳解
在合并數(shù)據(jù)的操作中,除了pd.concat()函數(shù),另一個常用的函數(shù)就是pd.merge()了,下面這篇文章主要給大家介紹了關(guān)于Python?Pandas數(shù)據(jù)合并pd.merge用法的相關(guān)資料,需要的朋友可以參考下2022-08-08
基于Python設(shè)計實現(xiàn)一個高級IP掃描工具
在網(wǎng)絡(luò)運維和安全審計工作中,IP掃描是基礎(chǔ)但至關(guān)重要的任務(wù),本文介紹一款基于Python開發(fā)的跨平臺IP掃描工具,它結(jié)合了簡潔的GUI界面和高效的掃描引擎,能夠快速檢測主機可達性2025-06-06
Python列表轉(zhuǎn)換為Excel表格第一列的方法詳解
在數(shù)據(jù)處理和分析的過程中,我們經(jīng)常需要將Python中的數(shù)據(jù)結(jié)構(gòu)(如列表)導(dǎo)出到Excel表格中,本文為大家整理了Python列表轉(zhuǎn)換為Excel表格第一列的幾種方法,希望對大家有所幫助2024-11-11
python可迭代類型遍歷過程中數(shù)據(jù)改變會不會報錯
這篇文章主要介紹了python可迭代類型遍歷過程中數(shù)據(jù)改變會不會報錯問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12
Python爬蟲實現(xiàn)selenium處理iframe作用域問題
這篇文章主要介紹了Python爬蟲實現(xiàn)selenium處理iframe作用域問題,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
Python wxPython庫使用wx.ListBox創(chuàng)建列表框示例
這篇文章主要介紹了Python wxPython庫使用wx.ListBox創(chuàng)建列表框,結(jié)合實例形式分析了wxPython庫使用wx.ListBox創(chuàng)建列表框的簡單實現(xiàn)方法及ListBox函數(shù)相關(guān)選項的功能,需要的朋友可以參考下2018-09-09
linux環(huán)境下安裝pyramid和新建項目的步驟
這篇文章簡單介紹了linux環(huán)境下安裝pyramid和新建項目的步驟,大家參考使用2013-11-11
python?pandas如何使用loc和iloc讀取行數(shù)據(jù)或列數(shù)據(jù)
這篇文章主要給大家介紹了關(guān)于python?pandas如何使用loc和iloc讀取行數(shù)據(jù)或列數(shù)據(jù)的相關(guān)資料,在學(xué)習(xí)機器學(xué)習(xí)的過程中對數(shù)據(jù)進行預(yù)處理時避免不了需要使用Pandas進行大量操,需要的朋友可以參考下2023-10-10

