[Python] 使用 pip 強制安裝同版本的 Python 套件

[Python] 使用 pip 強制安裝同版本的 Python 套件

專案在內部開發了一個 Python 套件放在 Git repo 裡面,

因此我們可以用 pip 來安裝,例如:

pip install git+https://github.com/platform/sdk-storage

 

不過今天同事更新了 Git repo 裡的東西,我一樣跑上面的指令,

卻發現套件似乎沒有更新…

安裝新版套件前,先執行了  pip freeze 來看一下版號:

$ pip freeze

sdk-storage-python @ git+https://github.com/platform/sdk-storage@59076bf036e59e31e03c427d4171ec7420a9f6db

 

但安裝新版套件後,那個 hash 值 5907… 的還是一模一樣,

表示它並沒有把新版的裝進去。

而且 pip install 的訊息裡只看到一堆相關的套件條件已滿足,

沒有去安裝指定套件的訊息:

$ pip install git+https://github.com/platform/sdk-storage@v1.0.21

Collecting git+https://github.com/platform/sdk-storage@v1.0.21
  Cloning https://github.com/platform/sdk-storage (to revision v1.0.21) to /private/var/folders/q8/mwx3fmws4dq0_73pykq37mnm0000gn/T/pip-req-build-b3g560uh
  Running command git clone --filter=blob:none --quiet https://github.com/platform/sdk-storage /private/var/folders/q8/mwx3fmws4dq0_73pykq37mnm0000gn/T/pip-req-build-b3g560uh
  Resolved https://github.com/platform/sdk-storage to commit d875436551541b5f0aa13952f5e63b56745b0733
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: azure-storage-blob<13.0.0,>=12.19.1 in ./venv/lib/python3.11/site-packages (from sdk-storage-python==0.1.0) (12.20.0)
Requirement already satisfied: boto3<2.0.0,>=1.34.85 in ./venv/lib/python3.11/site-packages (from sdk-storage-python==0.1.0) (1.34.113)
......

 

如果使用  pip install --upgrade 似乎也沒用…

查了一下,可以加上  --no-deps --force-reinstall ,

這會強制安裝套件,並且不更新相關的第三方套件。

 

執行之後,果然有相關訊息了:

$ pip install --upgrade --no-deps --force-reinstall git+https://github.com/platform/sdk-storage@v1.0.21

Collecting git+https://github.com/platform/sdk-storage@v1.0.21
......
Successfully built sdk-storage-python
Installing collected packages: sdk-storage-python
  Attempting uninstall: sdk-storage-python
    Found existing installation: sdk-storage-python 0.1.0
    Uninstalling sdk-storage-python-0.1.0:
      Successfully uninstalled sdk-storage-python-0.1.0
Successfully installed sdk-storage-python-0.1.0

 

再查看一次目前的版號,確實 hash 值有更新囉:

$ pip freeze

sdk-storage-python @ git+https://github.com/platform/sdk-storage@d875436551541b5f0aa13952f5e63b56745b0733

 

參考資料:python – Can I force pip to reinstall the current version?

(本頁面已被瀏覽過 19 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料