python項(xiàng)目下生成requirements.txt方法
一、使用pip freeae
pip freeze > requirements.txt
該命令存在局限:
該命令只會(huì)生成通過(guò)pip install 安裝的包
如果沒(méi)有創(chuàng)建Python的虛擬環(huán)境virtualenv,該命令會(huì)將環(huán)境中所有的包都輸出到requirements.txt文件,不管你當(dāng)前的Project有沒(méi)有用到這些包
二、使用pipreqs
Pipreqs 只會(huì)統(tǒng)計(jì)項(xiàng)目使用的包
2.1、安裝pipreqs
pip install pipreqs
2.2、使用方法
pipreqs "目錄" #在目錄下生成requirements.txt
2.3、特殊說(shuō)明
2.3.1、Mac 下沒(méi)法使用
pipreqs zsh: command not found: pipreqs
沒(méi)有找到使用辦法
2.3.2、Linux 使用報(bào)錯(cuò)
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.txt
2.3.3、Windows下使用
pipreqs "目錄" --encoding=utf8
三、更換環(huán)境后安裝requirements.txt
pip install -r requirements.txt
到此這篇關(guān)于python項(xiàng)目下生成requirements.txt方法的文章就介紹到這了,更多相關(guān)python requirements.txt內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python結(jié)合多線程爬取英雄聯(lián)盟皮膚(原理分析)
多線程是為了同步完成多項(xiàng)任務(wù),不是為了提高運(yùn)行效率,而是為了提高資源使用效率來(lái)提高系統(tǒng)的效率。這篇文章主要介紹了python爬取英雄聯(lián)盟皮膚結(jié)合多線程的方法,需要的朋友可以參考下2021-05-05PyQt5學(xué)習(xí)之QThread類的使用詳解
QThread是Qt線程類中最核心的底層類。要使用QThrea開(kāi)始一個(gè)線程,可以創(chuàng)建它的一個(gè)子類,然后覆蓋其QThread.run()函數(shù)。這篇文章就來(lái)和大家聊聊QThread類的使用,感興趣的可以學(xué)習(xí)一下2022-12-12Python?jpg快速轉(zhuǎn)png并調(diào)整大小方式
這篇文章主要介紹了Python實(shí)現(xiàn)jpg快速轉(zhuǎn)png并調(diào)整大小方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03