查找python項(xiàng)目依賴并生成requirements.txt

多人一起開發(fā)項(xiàng)目的時(shí)候總是要搭建環(huán)境和部署環(huán)境的,這個(gè)時(shí)候必須得有個(gè)python第三方包的list,一般都叫做requirements.txt。 如果一個(gè)項(xiàng)目使用時(shí)virtualenv環(huán)境,還好辦 pip freeze 就可以解決,但是如果一個(gè)項(xiàng)目的依賴list沒有維護(hù),而且又是環(huán)境混用,那就不好整理。不過,這里推薦一個(gè)python模塊pipreqs,可以自動(dòng)根據(jù)源碼生成 requirements.txt

pip freeze > requirements.txt
使用 pipreqs

這個(gè)工具的好處是可以通過對(duì)項(xiàng)目目錄的掃描,自動(dòng)發(fā)現(xiàn)使用了那些類庫,自動(dòng)生成依賴清單。

缺點(diǎn)是可能會(huì)有些偏差,需要檢查并自己調(diào)整下。

pip install pipreqs

使用方式也比較簡單

pipreqs ./

INFO: Starting new HTTPS connection (1): pypi.python.org
INFO: Starting new HTTPS connection (1): pypi.python.org
INFO: Starting new HTTPS connection (1): pypi.python.org
INFO: Starting new HTTPS connection (1): pypi.python.org
INFO: Starting new HTTPS connection (1): pypi.python.org
INFO: Starting new HTTPS connection (1): pypi.python.org
INFO: Successfully saved requirements file in ./requirements.txt

cat requirements.txt

chardet==2.0.1
colorama==0.2.5
configobj==4.7.2
Django==1.11.10
djangorestframework==3.7.7
gunicorn==19.7.1
html5lib==0.999
jieba==0.39
Landscape-Client==14.12
MySQL-python==1.2.3
numpy==1.14.0
PAM==0.4.2
pandas==0.22.0
Pillow==5.0.0
PyMySQL==0.8.0
pyOpenSSL==0.13
pyserial==2.6
python-apt===0.9.3.5ubuntu2
python-dateutil==2.6.1
python-debian===0.1.21-nmu2ubuntu2
python-igraph==0.6.5
pytz==2017.3
redis==2.10.6
requests==2.2.1
six==1.5.2
ssh-import-id==3.21
Twisted-Core==13.2.0
urllib3==1.7.1
zope.interface==4.0.5

原文網(wǎng)址:http://www.chenxm.cc/post/538.html

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容