jazzband / pip-tools

A set of tools to keep your pinned Python dependencies fresh.
https://pip-tools.rtfd.io
BSD 3-Clause "New" or "Revised" License
7.69k stars 610 forks source link

Resolver error on package version change #2114

Open ianrandman opened 1 month ago

ianrandman commented 1 month ago

Related issue: https://github.com/jazzband/pip-tools/issues/1977

When changing the version of a pinned dependency in requirements.in with an existing requirements.txt that includes an unpinned dependency that must change, pip-compile fails with a resolver error.

Environment Versions

  1. Windows 11
  2. Python 3.10.13
  3. pip 23.3.1
  4. pip-compile, version 7.4.1

Steps to replicate

$ rm -f requirements.in requirements.txt 

$ echo $'torch==2.2.2\ntorchvision' > requirements.in

$ pip-compile -q

$ grep 'torchvision' requirements.txt
    # via torchvision
    # via torchvision
    #   torchvision
torchvision==0.17.2

$ echo $'torch==2.3.1\ntorchvision' > requirements.in

$ pip-compile -q
  ERROR: Cannot install -r requirements.in (line 2) and torch==2.3.1 because these package versions have conflicting dependencies.
...
pip._vendor.resolvelib.resolvers.ResolutionImpossible: [RequirementInformation(requirement=SpecifierRequirement('torch==2.3.1'), parent=None), RequirementInformation(requirement=SpecifierRequirement('torch==2.2.2'), parent=LinkCandidate('https://files.pythonhosted.org/packages/0a/b8/027b3c36e61a26d14d4e9a8413d4a09e5fd8d3e01e3efce78447ca1dc3dd/torchvision-0.17.2-cp310-cp310-win_amd64.whl (from https://pypi.org/simple/torchvision/) (requires-python:>=3.8)'))]
...
pip._internal.exceptions.DistributionNotFound: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

$ rm requirements.txt 

$ pip-compile -q

$ grep 'torchvision' requirements.txt
    # via torchvision
    # via torchvision
    #   torchvision
torchvision==0.18.1

Expected result

Running pip-compile with the changed version for torch will automatically change the torchvision version to satisfy requirements.in instead of failing.

webknjaz commented 1 month ago

Could you include full file contents, not just parts of them?

ianrandman commented 1 month ago

Could you include full file contents, not just parts of them?

$ rm -f requirements.in requirements.txt 

$ echo $'torch==2.2.2\ntorchvision' > requirements.in

$ pip-compile -q
WARNING: --strip-extras is becoming the default in version 8.0.0. To silence this warning, either use --strip-extras to opt into the new default or use --no-strip-extras to retain the existing behavior.

$ cat requirements.txt
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile
#
filelock==3.15.4
    # via torch
fsspec==2024.6.1
    # via torch
jinja2==3.1.4
    # via torch
markupsafe==2.1.5
    # via jinja2
mpmath==1.3.0
    # via sympy
networkx==3.3
    # via torch
numpy==2.0.0
    # via torchvision
pillow==10.4.0
    # via torchvision
sympy==1.13.0
    # via torch
torch==2.2.2
    # via
    #   -r requirements.in
    #   torchvision
torchvision==0.17.2
    # via -r requirements.in
typing-extensions==4.12.2
    # via torch

$ echo $'torch==2.3.1\ntorchvision' > requirements.in

$ pip-compile -q
  ERROR: Cannot install -r requirements.in (line 2) and torch==2.3.1 because these package versions have conflicting dependencies.
...
pip._vendor.resolvelib.resolvers.ResolutionImpossible: [RequirementInformation(requirement=SpecifierRequirement('torch==2.3.1'), parent=None), RequirementInformation(requirement=SpecifierRequirement('torch==2.2.2'), parent=LinkCandidate('https://files.pythonhosted.org/packages/0a/b8/027b3c36e61a26d14d4e9a8413d4a09e5fd8d3e01e3efce78447ca1dc3dd/torchvision-0.17.2-cp310-cp310-win_amd64.whl (from https://pypi.org/simple/torchvision/) (requires-python:>=3.8)'))]
...
pip._internal.exceptions.DistributionNotFound: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

$ rm requirements.txt 

$ pip-compile -q
WARNING: --strip-extras is becoming the default in version 8.0.0. To silence this warning, either use --strip-extras to opt into the new default or use --no-strip-extras to retain the existing behavior.

$ cat requirements.txt
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile
#
filelock==3.15.4
    # via torch
fsspec==2024.6.1
    # via torch
intel-openmp==2021.4.0
    # via mkl
jinja2==3.1.4
    # via torch
markupsafe==2.1.5
    # via jinja2
mkl==2021.4.0
    # via torch
mpmath==1.3.0
    # via sympy
networkx==3.3
    # via torch
numpy==2.0.0
    # via torchvision
pillow==10.4.0
    # via torchvision
sympy==1.13.0
    # via torch
tbb==2021.13.0
    # via mkl
torch==2.3.1
    # via
    #   -r requirements.in
    #   torchvision
torchvision==0.18.1
    # via -r requirements.in
typing-extensions==4.12.2
    # via torch
webknjaz commented 1 month ago

Does using --upgrade help?

ianrandman commented 1 month ago

Does using --upgrade help?

Yes, but I do not want to upgrade packages unless necessary. My understanding is the same as in https://github.com/jazzband/pip-tools/issues/1977#issuecomment-1706831796. My intention is to maintain existing constraints when possible and only drop them if need be, which I believe is the intended behavior of pip-compile without --upgrade.

ianrandman commented 4 weeks ago

Any update on this?