Skip to content

Latest commit

 

History

History
92 lines (57 loc) · 2.72 KB

README.md

File metadata and controls

92 lines (57 loc) · 2.72 KB

pip-tools 教學

pip-tools 這個工具主要是幫你管理依賴套件的版本,

我們以 django=5.0.4 為例, 他肯定有自己的依賴套件,

怎麼保證下一次重新建立環境時候, 他的依賴套件版本會和我們以前建立的一樣呢?

萬一就是差那個版本號導致錯誤麼辦, 所以這個工具就是要解決這個問題.

安裝方法

pip install pip-tools

主要就兩個指令, 分別是 pip-compilepip-sync

先介紹 pip-compile, 使用前先把你要安裝的套件名稱寫在 requirements.in,

( 這裡面也可以指定版本, 例如 django<5.0.4)

然後執行 pip-compile, 執行後你會發現多了 requirements.txt,

#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile
#
asgiref==3.8.1
    # via django
async-timeout==4.0.3
    # via redis
django==5.0.4
    # via -r requirements.in
redis==5.0.3
    # via -r requirements.in
sqlparse==0.5.0
    # via django
typing-extensions==4.11.0
    # via asgiref

這時候這些套件還沒有安裝到環境上(可用 pip freeze 確認),

如果你要安裝,

請再執行 pip-sync,

套件被成功安裝到環境上了 (可用 pip freeze 確認).

這邊的好處是他可以幫你鎖住版本, 避免不必要的錯誤.

特別提一下 Updating requirements,

如果你執行 pip-compile 時, 還沒有 requirements.txt, 這時候都會安裝最新的版本(或是你指定的版本),

如果你執行 pip-compile 時, 已經有 requirements.txt, 這時候就算 dep 可以更新, 它將不會幫你更新.

如果你想要執行 pip-compile 時, 已經有 requirements.txt, 而且要更新存在的全部套件, 使用 pip-compile --upgrade,

假如你只想要更新特定的 package, 使用 pip-compile --upgrade-package redis

Reference

Donation

文章都是我自己研究內化後原創,如果有幫助到您,也想鼓勵我的話,歡迎請我喝一杯咖啡 😆

綠界科技ECPAY ( 不需註冊會員 )

alt tag

贊助者付款

歐付寶 ( 需註冊會員 )

alt tag

贊助者付款

贊助名單

贊助名單

License

MIT license