如何使用pipenv解决Python包依赖关系?

问题描述 投票:0回答:14

我正在使用

pipenv
来处理 Python 包依赖项。

Python 包使用两个包(名为

pckg1
pckg2
),它们依赖于名为
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.

按照建议,

pipenv install --skip-lock
可以解决问题,但依赖关系树仍未解决。

我很乐意告诉

Pipenv
覆盖
pckg2
的要求,并指定
pckg3>=4.1.0

如何解决这个问题?

python python-3.x pip dependencies pipenv
14个回答
81
投票

我经常遇到这个错误。清除锁定文件中的缓存每次都很有效。

$ pipenv lock --pre --clear


21
投票

你不能。目前,

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
依赖项的角色,但我在这里没有看到任何更好的方法。


5
投票

当 pipfile 上有未完成的例程时,此方法有效。

一旦我犯了错误并逃跑了

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

并且 Pipenv 总是尝试完成安装但没有成功,因为该库不存在。我用以下方法解决了这个问题:

pipenv uninstall codecove

然后安装了codecov。

我试着跑

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

但只有在卸载了名称错误的库后我才成功。


3
投票

我也有类似的问题

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. pipenv 更新

2
投票

如果您收到如下错误:

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

对我来说,发生这种情况是因为底层虚拟环境没有引用我当前的目录。

我通过将内容移动到新目录并删除旧目录解决了这个问题。

我还必须删除

Pipfile
Pipfile.lock
,但我不确定这是否有必要。


1
投票

我也遇到了同样的情况,我正在使用 Visual Studio Code,并且我能够摆脱它:

  • 从 python 文件夹中删除除 *.py 之外的所有文件(.vscode、pycache、* 该文件夹内的虚拟环境)
  • 创建一个新的virtualenv env(名称)
  • 新建\脚本激活.bat

然后尝试安装虚拟文件夹缺少的依赖项,一切顺利,它对我有用。


0
投票

我对 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?

0
投票

在 Windows 10 上使用 VS Code,经过一番折腾后,我通过在 Powershell 中运行 pipelinev 获得了全新安装。 我还删除了之前尝试的所有痕迹(新目录删除了之前的venvs)。


0
投票

这里没有任何东西对我有用。最终解决了这个问题:

pip uninstall pipenv
pip install pipenv

0
投票

如果您遇到

Locking Failed!
错误:

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

清除pipfile.lock

上的缓存
卸载你的软件包并重新启动虚拟机对我来说是成功的。

尝试:

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

停止并销毁虚拟机

重新启动虚拟机

希望这有帮助!


0
投票
pip install -U pipenv     

在 Ubuntu 21.04 - Hirsute Hippo - python 版本 3.9.5 上为我解决了

此命令安装了这些软件包:

  • appdirs-1.4.4
  • 证书-2021.5.30
  • distlib-0.3.2
  • 文件锁-3.0.12
  • pipenv-2021.5.29
  • 六-1.16.0
  • virtualenv-20.4.7
  • virtualenv-clone-0.5.4

0
投票

在 virtualenv 内更新

pip
对我有用:
py -m pip install --upgrade pip


0
投票

这也可能是因为您有一个旧的 pipelinev 环境,您需要在创建新环境之前清理它。

pipenv --rm
pipenv install

-2
投票
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

© www.soinside.com 2019 - 2024. All rights reserved.