[英]How to autoremove dependent Python packages within a pipenv when uninstalling a package?
當您使用pipenv
安裝 package 時,所有依賴包也將隨之安裝。 使用pipenv uninstall
不會自動刪除依賴包。
如何在 pipenv 中獲得pip-autoremove
的等效功能?
例如:
$ cd testpipenv
$ pipenv install requests
$ pipenv shell
(testpipenv) $ pipenv graph
requests==2.24.0
- certifi [required: >=2017.4.17, installed: 2020.6.20]
- chardet [required: >=3.0.2,<4, installed: 3.0.4]
- idna [required: >=2.5,<3, installed: 2.10]
- urllib3 [required: >=1.21.1,<1.26,!=1.25.1,!=1.25.0, installed: 1.25.9]
(testpipenv) $ pipenv uninstall requests
(testpipenv) $ pip list
Package Version
---------- ---------
certifi 2020.6.20
chardet 3.0.4
idna 2.10
pip 20.1.1
setuptools 47.3.1
urllib3 1.25.9
wheel 0.34.2
requests
的依賴包,如urllib3
,仍然安裝,可以通過
(testpipenv) $ python
>>> import urllib3
此處也對此進行了討論: Pipenv uninstall doesn't uninstall dependencies - issue #1470 ,我還沒有找到關於使用 pipenv 自動刪除軟件包的最新說明集。
使用的版本:
TL;博士
(testpipenv) $ pipenv uninstall requests && pipenv clean
為了僅使用pipenv
命令獲得與pip-autoremove
類似的功能,我執行了以下操作,繼續上面的示例:
(testpipenv) $ pipenv graph
certifi==2020.6.20
chardet==3.0.4
idna==2.10
urllib3==1.25.9
這表明仍然安裝了依賴包,但它們已從 Pipfile.lock 中刪除。 因此,使用pipenv clean
將刪除它們:
(testpipenv) $ pipenv clean
Uninstalling certifi…
Uninstalling idna…
Uninstalling urllib3…
Uninstalling chardet…
總之...
(testpipenv) $ pipenv uninstall requests && pipenv clean
... 將刪除所有依賴包,並且與pip-autoremove
最接近。
這可能比預期的更激進,因為clean
命令“卸載 Pipfile.lock 中未指定的所有包” 如果在使用 clean 之前未將包添加到 Pipfile.lock,則此命令可能會刪除超出預期的內容。 我不知道這是否真的是一個問題,因為uninstall
會自動更新 Pipfile.lock ,除非指定了其他選項,例如--skip-lock
。
另一種選擇是...
pipenv --rm && pipenv install
...這將刪除所有內容並基於 Pipfile.lock 重建虛擬環境。 這會起作用,但速度很慢,因為它會刪除完整的虛擬環境並重新安裝所有東西,除了不需要的依賴項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.