I have a package P that depends on a package A. Package A depends on packages B and C==3. At the same time, Package B depends on C==4.
This creates conflicts and an akward error message is shown in red every time I pip install packages P or 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. However, package P has a command line application, which raises an error as long as you have the install conflicts inherited from 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. In fact, my CLI is a class wrapped by fire, which I can call without problems in an interactive session.
The error trace shows pkg_resources.ContextualVersionConflict in the end, which I never call in 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?
I am also interested to know what is happening under the hood.
Bytheway, I am always installing P in a new Conda environment.
For package B there is only one version available, not multiple versions.
Thanks!
From what I understood the version of B is not constrained by A, so basically any version of B would be acceptable. Now, maybe there is a version of B that has
C==3in its dependencies. If such a version of B exists, let's say it'sB==5, then the following could work:If it does indeed work, for a long term solution, you might want to try one of the following:
B==5constraint on your project P, since you have control over it. I probably wouldn't recommend it though, since B is not actually a direct dependency of P.constraints.txtfile containingB==5and call pip with the--constraintoption:path/to/pythonX.Y -m pip install --constraint constraints.txt PAdditionnally I would recommend giving pip's new, experimental dependency resolver a try. It might be better at finding the right combination or projects to install in such situations.
See this answer for details: