查找python項目依賴並生成requirements.txt——pipreqs 真是很好用啊


查找python項目依賴並生成requirements.txt

轉自:http://blog.csdn.net/orangleliu/article/details/60958525

一起開發項目的時候總是要搭建環境和部署環境的,這個時候必須得有個python第三方包的list,一般都叫做requirements.txt。 如果一個項目使用時virtualenv環境,還好辦 pip freeze 就可以解決,但是如果一個項目的依賴list沒有維護,而且又是環境混用,那就不好整理的呀,不過,這里安利一個工具 pipreqs,可以自動根據源碼生成 requirements.txt .

使用pip freeze

$ pip freeze > requirements.txt

這種方式配合virtualenv 才好使,否則把整個環境中的包都列出來了。

使用 pipreqs

這個工具的好處是可以通過對項目目錄的掃描,自動發現使用了那些類庫,自動生成依賴清單。

缺點是可能會有些偏差,需要檢查並自己調整下。

# 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 Django == 1.6 django_redis == 4.3.0 redis == 2.10.5 django_redis_cache == 1.6.5 simplejson == 3.8.2 Twisted == 16.0.0 pycrypto == 2.6.1 ConcurrentLogHandler == 0.9.1 cx_Oracle == 5.2.1 ujson == 1.35

有時候結果可能會有些偏差,這里並沒有用Oracle的相關驅動,根據的需要修改 requirements.txt 就好了。

how python project auto generate requirements.txt ?


免責聲明!

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



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