Python/pip如何处理冲突的传递依赖项? [英] How does Python / pip handle conflicting transitive dependencies?

查看:594
本文介绍了Python/pip如何处理冲突的传递依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我要安装软件包a,它需要软件包b1b2.反过来,b1需要c > 1.0.0b2需要c < 1.0.0.因此,使用同一软件包不能同时满足b1b2的要求.

Suppose I want to install package a which requires the packages b1 and b2. In turn, b1 requires c > 1.0.0 and b2 requires c < 1.0.0. So the requirements of b1 and b2 cannot be fulfilled at the same time with the same package.

原则上/其他编程语言,这不是问题.一个人可以并排安装两个版本的c,并确保b1使用的版本不是b2.

In principle / other programming languages, this is not a problem. One could install two versions of c side by side and make sure that b1 uses another version than b2.

但是,我不确定pip是否可以安装同一软件包的两个版本.我的第一个问题是:pip可以安装一个软件包的两个版本吗?

However, I'm not sure if pip can install two versions of the same package. My first question is: Can pip install two versions of one package?

我的主要问题是人们实际上如何处理这一问题.我现在能想象的唯一方法是

My main question is how one actually can deal with that problem. The only ways I can imagine right now is to

  1. 叉子b1(或b2)和适用于叉子的c版本,然后将b1_forkedc_for_b1_forked上载到PyPI,或者
  2. b1(或b2)的代码直接包含在我的项目中
  1. fork b1 (or b2) and a version of c that works for the fork, and upload b1_forked and c_for_b1_forked to PyPI, or
  2. Include the code of b1 (or b2) directly in my project

两者似乎都比必要的多.

Both seem more problematic than necessary.

>>> import natsort; print(natsort.__file___)
'/home/moose/.local/lib/python3.6/site-packages/natsort/__init__.py'

$ cd /home/moose/.local/lib/python3.6/site-packages
$ ls
[... a lot of *.dist-info directories, some .py files, some .so files, ]
[... some directories called like the packages I've installed]

所以我很确定这是Python查找已安装软件包的地方,并且只安装了一个版本(尽管*-dist-info目录使我有些困惑).

So I'm pretty sure this is where Python looks for installed packages and that only one version is installed (although the *-dist-info directories confuse me a bit).

此博客文章建议目前,没有很好的解决方案来解决传递依赖的冲突.其他项目(例如诗歌)对此有帮助吗?

This blog post suggests that there is no good solution for conflicting transitive dependencies at the moment. Do other projects (e.g. poetry) help with that?

推荐答案

原则上/其他编程语言,这不是问题.一个人可以并排安装两个版本的c,并确保b1使用的版本不是b2.

In principle / other programming languages, this is not a problem. One could install two versions of c side by side and make sure that b1 uses another version than b2.

这不是解决方案.如果c迟早要管理共享资源(例如,控制台),则b1b2会通过不同的c相互占用彼此的输入或输出,最终您将得到不正确的输入和垃圾输出.

That's not a solution. If c manages a shared resource (console, e.g.) sooner or later b1 and b2 will stomp each other input or output via different cs and you end up with incorrect input and garbage output.

您描述的是一个普遍的问题,不仅限于Python或pip.唯一的解决方案是更改b1和/或b2以同意c的版本.降级b1以允许c < 1.0或升级b2以允许c > 1.0.

What you describe is a general problem, not limited to Python or pip. The only solution is to change b1 and/or b2 to agree on a version of c. Either downgrade b1 to allow c < 1.0 or upgrade b2 to allow c > 1.0.

pip可以安装一个软件包的两个版本吗?

Can pip install two versions of one package?

否,问题不在pip中,而是在Python中:其导入系统不允许从同一软件包的不同版本进行导入.您可以查看 mitsuhiko/multiversion (仅适用于Python2).

No, and the problem is not in pip but in Python: its import system doesn't allow importing from different versions of the same package. You can look at mitsuhiko/multiversion (Python2-only).

这篇关于Python/pip如何处理冲突的传递依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆