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

新手上路,请多包涵

我正在使用 pipenv 来处理 Python 包依赖项。

Python 包使用两个包(名为 pckg1pckg2 ),它们依赖于名为 pckg3 ,67 的同一个包, 但来自两个不同的版本—显示依赖树:

 $ 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

如何解决?

原文由 Val Berthe 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 673
2 个回答

我经常收到那个错误。每次清除锁定文件中的缓存都非常有效。

$ pipenv lock --pre --clear

原文由 arshbot 发布,翻译遵循 CC BY-SA 4.0 许可协议

你不能。目前, pipenv 没有提供任何明确覆盖需求约束的方法。

As a workaround, you can put dependencies that you want to override to dev-packages as those will be overridden by packages , so this Pipfile should install 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 依赖的角色,但我在这里看不到更好的方法。

原文由 hoefling 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题