2

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!

srcolinas
  • 497
  • 5
  • 13
  • Am I understanding it right that the dependencies of `A` contradict themselves? Is `A` a public project? I would be interested to see this more in details. – sinoroc Jul 19 '20 at 14:07
  • `A` is not a public project, but out of my scope. The dependencies of `A` do not contradict, but have a conflict with the dependencies of `B`. The conflict is only evident for a couple of functions that one may decide not to use. – srcolinas Jul 19 '20 at 14:17

1 Answers1

0

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==3 in its dependencies. If such a version of B exists, let's say it's B==5, then the following could work:

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:

  • Set a B==5 constraint 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.
  • Use a constraints.txt file containing B==5 and call pip with the --constraint option:
    • path/to/pythonX.Y -m pip install --constraint constraints.txt P

Additionnally 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.

path/to/pythonX.Y -m pip --unstable-feature=resolver install P

See this answer for details:

sinoroc
  • 18,409
  • 2
  • 39
  • 70
  • Sorry, I did not specify that there is only one possible version of dependency `B` – srcolinas Jul 19 '20 at 20:08
  • Then `A` could never ever work to begin with, could it. The whole thing doesn't make any sense, or I am missing something entirely. -- If we exclude `P` from the equation, is there a version of `A` with its dependencies that has no conflict? – sinoroc Jul 23 '20 at 14:19
  • @sinroc `A` always have that conflict, but that does not mean `A` does not work. As I said, everything works if I use a Python interactive session but not if I run the script from the command line. – srcolinas Jul 23 '20 at 20:48