多人一起開發(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