[英]Version conflicts for Python apps but not for interactive development
I have a package P
that depends on a package A
.我有一个 package
P
取决于 package A
。 Package A
depends on packages B
and C==3
. Package
A
取决于包B
和C==3
。 At the same time, Package B
depends on C==4
.同时, Package
B
依赖于C==4
。
This creates conflicts and an akward error message is shown in red every time I pip install packages P
or A
.这会产生冲突,并且每次我 pip 安装软件包
P
或A
时都会以红色显示错误消息。
Now, I know I can run packages P
and A
just fine if I import them in an interactive terminal or Jupyter notebook and I call the functions and classes I need.现在,我知道如果我将包
P
和A
导入交互式终端或 Jupyter 笔记本并调用我需要的函数和类,我可以很好地运行它们。 However, package P
has a command line application, which raises an error as long as you have the install conflicts inherited from package A
.但是, package
P
有一个命令行应用程序,只要您有从 package A
继承的安装冲突,就会引发错误。
This error is not raised by me, it is raised by the Python interpreter alone (I think), since I am not calling any new functionality compared to when I use P
as a library.这个错误不是我提出的,它是由 Python 解释器单独提出的(我认为),因为与使用
P
作为库时相比,我没有调用任何新功能。 In fact, my CLI is a class wrapped by fire
, which I can call without problems in an interactive session.事实上,我的 CLI 是一个被
fire
包裹的 class ,我可以在交互式 session 中毫无问题地调用它。
The error trace shows pkg_resources.ContextualVersionConflict
in the end, which I never call in P
.错误跟踪最后显示
pkg_resources.ContextualVersionConflict
,我从未在P
中调用它。
Given that I can only control what happens in package P
, is there a way for make it work directly as a command line app?鉴于我只能控制 package
P
中发生的事情,有没有办法让它直接作为命令行应用程序工作?
I am also interested to know what is happening under the hood.我也很想知道幕后发生了什么。
Bytheway, I am always installing P
in a new Conda environment.顺便说一句,我总是在新的 Conda 环境中安装
P
For package B
there is only one version available, not multiple versions.对于 package
B
,只有一个版本可用,而不是多个版本。
Thanks!谢谢!
From what I understood the version of B is not constrained by A , so basically any version of B would be acceptable.据我了解, B的版本不受A 的限制,因此基本上任何版本的B都是可以接受的。 Now, maybe there is a version of B that has
C==3
in its dependencies.现在,也许有一个版本的B在其依赖项中有
C==3
。 If such a version of B exists, let's say it's B==5
, then the following could work:如果存在这样的B版本,假设它是
B==5
,那么以下可以工作:
path/to/pythonX.Y -m pip install P B==5
If it does indeed work, for a long term solution, you might want to try one of the following:如果它确实有效,对于长期解决方案,您可能需要尝试以下方法之一:
B==5
constraint on your project P , since you have control over it.B==5
约束,因为您可以控制它。 I probably wouldn't recommend it though, since B is not actually a direct dependency of P .constraints.txt
file containing B==5
and call pip with the --constraint
option :B==5
的constraints.txt
文件并使用--constraint
选项调用pip :
path/to/pythonX.Y -m pip install --constraint constraints.txt P
Additionnally I would recommend giving pip 's new, experimental dependency resolver a try.另外,我建议尝试 pip的新的实验性依赖解析器。 It might be better at finding the right combination or projects to install in such situations.
在这种情况下,找到合适的组合或安装项目可能会更好。
path/to/pythonX.Y -m pip --unstable-feature=resolver install P
See this answer for details:有关详细信息,请参阅此答案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.