如果两个 python 包具有不同版本的包依赖项怎么办?

What if two python packages have different versions of package dependencies?

我对 python 依赖关系感到困惑。

在下面的例子中,C 将安装 2 个不同的版本?或者 AB 都使用 C 版本 2.0?

这个问题取决于您使用的包管理器以及它如何解决依赖冲突。如果您使用的是标准包管理器 (pip),那么它应该会在出现此类错误时通知您。 pip 的工作方式是通过一个称为 "backtracking", which essentially works "backwards" from the latest version to find the most recent version that a package is compatible with. In the event that two packages ask for conflicting versions of another package, you get what's known as a ResolutionImpossible error 的进程,它将取消安装进程。这通常只能通过强制 pip 选择特定版本或更新您尝试安装的软件包的 requirements.txt 文件来解决。 conda 以类似的方式工作,但它通常会求助于安装最新版本,然后警告您而不是 pip 抛出的错误。