How does PIP determine the version of a dependency of multiple dependents

最后都变了- 提交于 2020-07-31 03:46:27

问题


Let's assume we have the following dependency tree in Python using PIP as package installer:

A==1.2.1:
|  - B==1.5.4
|  - C==?.?.?

D==1.3.0:
|  - C==?.?.?

Let's also assume that the existing versions of package C are the followings:

- 0.0.8
- 1.0.2

As we know, PIP will not install different versions of the same package into an environment. Which means it has to pick one suitable version for all dependents.

What I simply cannot understand how PIP determines the suitable version.

If package A depends on C==0.0.8 and package D depends on C==1.0.2, this situation cannot get easily handled, unlike other package managers such as NPM could do.


回答1:


When pip installs a package, it automatically installs any dependent Python packages without checking if these conflict with previously installed packages. It will install a package and any of its dependencies regardless of the state of the existing installation. Because of this, a user with a working installation of, for example, Google Tensorflow, can find that it stops working having used pip to install a different package that requires a different version of the dependent NumPy library than the one used by Tensorflow. In some cases, the package may appear to work but produce different results in detail.

Anaconda (Python distribution) - Wikipedia




回答2:


On this topic, things will change relatively soon. Since pip's developers are currently working on a new dependency resolver:

  • https://pyfound.blogspot.com/2020/03/new-pip-resolver-to-roll-out-this-year.html

To test it today, you might want to install pip 20.2b1 and enable the unstable feature "resolver", with for example either one of the following:

  • PIP_UNSTABLE_FEATURE=resolver python -m pip install SomeProject
  • python -m pip --unstable-feature=resolver install SomeProject

See the following link for more details:

  • https://discuss.python.org/t/announcement-pip-20-2b1-release/4242

Other references:

  • http://www.ei8fdb.org/thoughts/2020/05/test-pips-alpha-resolver-and-help-us-document-dependency-conflicts/
  • https://pradyunsg.me/blog/2020/03/27/pip-resolver-testing/
  • https://www.pythonpodcast.com/pip-resolver-dependency-management-episode-264/

Update pip 20.2

  • https://pythoninsider.blogspot.com/2020/07/upgrade-pip-20-2-changes-20-3.html


来源:https://stackoverflow.com/questions/62677190/how-does-pip-determine-the-version-of-a-dependency-of-multiple-dependents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!