一起開發項目的時候總是要搭建環境和部署環境的,這個時候必須得有個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.orgINFO: Starting new HTTPS connection (1): pypi.python.orgINFO: Starting new HTTPS connection (1): pypi.python.orgINFO: Starting new HTTPS connection (1): pypi.python.orgINFO: Starting new HTTPS connection (1): pypi.python.orgINFO: Starting new HTTPS connection (1): pypi.python.orgINFO: Successfully saved requirements file in ./requirements.txtcat requirements.txtDjango == 1.6django_redis == 4.3.0redis == 2.10.5django_redis_cache == 1.6.5simplejson == 3.8.2Twisted == 16.0.0pycrypto == 2.6.1ConcurrentLogHandler == 0.9.1cx_Oracle == 5.2.1ujson == 1.35
有時候結果可能會有些偏差,這里并沒有用Oracle的相關驅動,根據的需要修改 requirements.txt 就好了。
how python project auto generate requirements.txt ?
以上這篇查找python項目依賴并生成requirements.txt的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答