1 回答

慕俠2389804
TA貢獻1719條經(jīng)驗 獲得超6個贊
一起開發(fā)項目的時候總是要搭建環(huán)境和部署環(huán)境的,這個時候必須得有個Python第三方包的list,一般都叫做requirements.txt。 如果一個項目使用時virtualenv環(huán)境,還好辦 pip freeze 就可以解決,但是如果一個項目的依賴list沒有維護,而且又是環(huán)境混用,那就不好整理的呀,不過,這里安利一個工具 pipreqs,可以自動根據(jù)源碼生成 requirements.txt .
使用pip freeze
$ pip freeze > requirements.txt11
這種方式配合virtualenv 才好使,否則把整個環(huán)境中的包都列出來了。
使用 pipreqs
這個工具的好處是可以通過對項目目錄的掃描,自動發(fā)現(xiàn)使用了那些類庫,自動生成依賴清單。
缺點是可能會有些偏差,需要檢查并自己調整下。
# 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.351234567891011121314151617181920212223242512345678910111213141516171819202122232425
有時候結果可能會有些偏差,這里并沒有用Oracle的相關驅動,根據(jù)的需要修改 requirements.txt 就好了。
how python project auto generate requirements.txt ?
使用pip freeze
$ pip freeze > requirements.txt11
這種方式配合virtualenv 才好使,否則把整個環(huán)境中的包都列出來了。
使用 pipreqs
這個工具的好處是可以通過對項目目錄的掃描,自動發(fā)現(xiàn)使用了那些類庫,自動生成依賴清單。
缺點是可能會有些偏差,需要檢查并自己調整下。
# 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.351234567891011121314151617181920212223242512345678910111213141516171819202122232425
有時候結果可能會有些偏差,這里并沒有用Oracle的相關驅動,根據(jù)的需要修改 requirements.txt 就好了。
how python project auto generate requirements.txt ?
- 1 回答
- 0 關注
- 5709 瀏覽
添加回答
舉報
0/150
提交
取消