簡體   English   中英

如何用pipenv解決Python package依賴?

[英]How to resolve Python package dependencies with pipenv?

我正在使用pipenv來處理 Python package 依賴項。

Python package 使用兩個包(名為pckg1pckg2 ),它們依賴於同一個名為 pckg3 的pckg3但來自兩個不同的版本 顯示依賴樹:

$ pipenv graph
  pckg1==3.0.0
    - pckg3 [required: >=4.1.0]
  pckg2==1.0.2
    - pckg3 [required: ==4.0.11]

嘗試安裝依賴項:

$ pipenv install

Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
You can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
Hint: try $ pipenv lock --pre if it is a pre-release dependency.
Could not find a version that matches pckg3==4.0.11,==4.1.0,>=4.1.0 (from -r C:\Users\user\AppData\Local\Temp\pipenv-o7uxm080-requirements\pipenv-hwekv7dc-constraints.txt (line 2))
Tried: 3.3.1, 3.3.2, 3.3.3, 3.4.0, 3.4.2, 4.0.0, 4.0.0, 4.0.1, 4.0.1, 4.0.2, 4.0.2, 4.0.3, 4.0.3, 4.0.4, 4.0.4, 4.0.6, 4.0.6, 4.0.8, 4.0.8, 4.0.9, 4.0.9, 4.0.10, 4.0.10, 4.0.11, 4.0.11, 4.1.0, 4.1.0, 4.1.1, 4.1.1, 4.1.2, 4.1.2, 4.2.1, 4.2.1, 4.3.0, 4.3.0
There are incompatible versions in the resolved dependencies.

正如建議的那樣, pip install --skip-lock可以解決問題,但依賴關系樹仍未解決。

我很想告訴Pipenv覆蓋pckg2的要求,並指定pckg3>=4.1.0

如何解決?

我不斷收到該錯誤。 每次清除鎖定文件中的緩存都非常有效。

$ pipenv lock --pre --clear

你不能。 目前, pipenv不提供任何顯式覆蓋需求約束的內容。

作為一種解決方法,您可以將要覆蓋的依賴項放在dev-packages因為這些依賴項將被packages覆蓋,因此此Pipfile應安裝pckg3>=4.1.0

# Pipfile
...
[packages]
pckg1 = "==3.0.0"

[dev-packages]
pckg2 = "==1.0.2"

如果您現在鎖定並安裝:

$ pipenv lock --dev
$ pipenv install --dev

要求==4.0.11將被>=4.1.0覆蓋。 如果您問我,這很丑陋,因為這不是開發包的用途,而且您正在更改項目中pckg2依賴項的角色,但我在這里看不到任何更好的方法。

當 pipfile 上有未完成的例程時,這會起作用。

一旦我犯了一個錯誤並運行

pipenv install codecove # With an 'e' at the end

並且 pipenv 一直試圖完成安裝但沒有成功,因為 lib 不存在。 我解決了它:

pipenv uninstall codecove

並在之后安裝了 codecov。

我試着跑

pipenv lock --clear
pipenv lock --pre --clear

但只有在卸載了錯誤名稱的 lib 后,我才成功。

我有與google-cloud-core類似的問題。

$ pipenv lock
Locking [dev-packages] dependencies…
Locking [packages] dependencies…

Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
  First try clearing your dependency cache with $ pipenv lock --clear, then try the original command again.
 Alternatively, you can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
  Hint: try $ pipenv lock --pre if it is a pre-release dependency.
Could not find a version that matches google-cloud-core<0.29dev,<0.30dev,>=0.28.0,>=0.29.0
Tried: 0.20.0, 0.20.0, 0.21.0, 0.21.0, 0.22.0, 0.22.0, 0.22.1, 0.22.1, 0.23.0, 0.23.0, 0.23.1, 0.23.1, 0.24.0, 0.24.0, 0.24.1, 0.24.1, 0.25.0, 0.25.0, 0.26.0, 0.26.0, 0.27.0, 0.27.0, 0.27.1, 0.27.1, 0.28.0, 0.28.0, 0.28.1, 0.28.1, 0.29.0, 0.29.0
There are incompatible versions in the resolved dependencies.

它被解決了

  1. rm -rf pipfile.lock
  2. 管道更新

如果您收到如下錯誤:

Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✘ Locking Failed! 

對我來說,這是因為底層虛擬環境沒有引用我的當前目錄。

我通過將內容移動到新目錄並刪除舊目錄解決了這個問題。

我還必須刪除PipfilePipfile.lock但我不確定是否有必要。

它發生在我身上,我正在使用 Visual Studio Code 並且能夠擺脫它:

  • 從你的 python 文件夾中刪除除 *.py 之外的所有文件(.vscode、 pycache 、* 該文件夾中的虛擬環境)
  • 創建一個新的 virtualenv env(name)
  • 新\\腳本\\激活.bat

然后嘗試為虛擬文件夾安裝缺少的依賴項,一切順利,它對我有用。

如果你遇到了Locking Failed! 錯誤:

Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✘ Locking Failed!

清除pipfile.lock的緩存卸載您的軟件包並重新啟動 VM對我來說很有效。

嘗試:

pipenv uninstall *YourPackage*
pipenv uninstall *YourPackage* --dev   ##(if relevant to your package)
pipenv lock --clear

停止並銷毀虛擬機

重啟虛擬機

希望這可以幫助!

我對 glob 模塊有類似的問題。 我從 Pipfile 中刪除了glob = "*" ,之后它工作正常。

錯誤:

bash-4.2# pipenv lock  --clear
Locking [dev-packages] dependencies…
✔ Success! 
Locking [packages] dependencies…
✘ Locking Failed! 
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/resolver.py", line 69, in resolve
[pipenv.exceptions.ResolutionFailure]:       req_dir=requirements_dir
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/utils.py", line 726, in resolve_deps
[pipenv.exceptions.ResolutionFailure]:       req_dir=req_dir,
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/utils.py", line 480, in actually_resolve_deps
[pipenv.exceptions.ResolutionFailure]:       resolved_tree = resolver.resolve()
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/utils.py", line 395, in resolve
[pipenv.exceptions.ResolutionFailure]:       raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]:       pipenv.exceptions.ResolutionFailure: ERROR: ERROR: Could not find a version that matches glob
[pipenv.exceptions.ResolutionFailure]:       No versions found
[pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
  First try clearing your dependency cache with $ pipenv lock --clear, then try the original command again.
 Alternatively, you can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
  Hint: try $ pipenv lock --pre if it is a pre-release dependency.
ERROR: ERROR: Could not find a version that matches glob
No versions found
Was https://pypi.org/simple reachable?
[pipenv.exceptions.ResolutionFailure]:       req_dir=requirements_dir
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/utils.py", line 726, in resolve_deps
[pipenv.exceptions.ResolutionFailure]:       req_dir=req_dir,
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/utils.py", line 480, in actually_resolve_deps
[pipenv.exceptions.ResolutionFailure]:       resolved_tree = resolver.resolve()
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/utils.py", line 395, in resolve
[pipenv.exceptions.ResolutionFailure]:       raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]:       pipenv.exceptions.ResolutionFailure: ERROR: ERROR: Could not find a version that matches glob
[pipenv.exceptions.ResolutionFailure]:       No versions found
[pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
  First try clearing your dependency cache with $ pipenv lock --clear, then try the original command again.
 Alternatively, you can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
  Hint: try $ pipenv lock --pre if it is a pre-release dependency.
ERROR: ERROR: Could not find a version that matches glob
No versions found
Was https://pypi.org/simple reachable?

在使用 VS Code 的 Windows 10 上,通過在 Powershell 中運行 pipenv,我得到了一個全新的安裝。 我還刪除了以前嘗試的所有痕跡(新目錄刪除了以前的 venvs)。

這里沒有什么對我有用。 最終解決了這個問題:

pip uninstall pipenv
pip install pipenv
pip install -U pipenv     

在 Ubuntu 21.04 - Hirsute Hippo - python 版本 3.9.5 上為我解決

此命令安裝了這些軟件包:

  • appdirs-1.4.4
  • 證書 2021.5.30
  • distlib-0.3.2
  • filelock-3.0.12
  • pipenv-2021.5.29
  • 六-1.16.0
  • virtualenv-20.4.7
  • virtualenv-clone-0.5.4

在 virtualenv 中更新pip對我有用: py -m pip install --upgrade pip

這也可能是因為您有一個舊的 pipenv 環境,您需要在創建新環境之前清理它。

pipenv --rm
pipenv install
pipenv lock
Locking [dev-packages] dependencies…
Locking [packages] dependencies…

Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
  First try clearing your dependency cache with $ pipenv lock --clear, then try the original command again.
 Alternatively, you can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
  Hint: try $ pipenv lock --pre if it is a pre-release dependency.

pipenv 安裝 --clean

vi Pipfile 並刪除有問題的包。 為我工作得很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM