Skip to content

pip verifies package dependency requirements before verifying package python requirements #13146

@gdurif

Description

@gdurif

Description

When installing a package with a specific Python version requirements (specified by the requires-python field in the pyproject.toml file), pip checks other requirements (from dependencies) before checking the package specific Python requirement, ending up in useless package downloading and checking if this Python requirement is not met.

In addition, if another issue is met during the checking of dependency requirements, the user is not advertised that the current Python version is not supported by the package (c.f. MWE below).

Expected behavior

pip should check the package Python requirements before checking other dependency requirements to avoid useless actions if this requirements is not met.

pip version

24.3.1

Python version

3.13.1

OS

Linux

How to Reproduce

I have set up a dummy package (https://github.com/gdurif/dummy_pypkg) for testing purpose, with a Python requirement requires-python = ">=3.11,<3.13".

I am trying to install it with Python 3.13+.

  • Case 1 (c.f. below): I have set up a branch called ok where the package has no dependency. In that case, pip tells me that the Python version is not supported.
  • Case 2 (c.f. below): I have set up a branch called nok where the package has one dependency "tensorflow>=2.14.0". In that case, pip downloads the dependency (if not cached) and checks its requirements before checking my package Python requirement, ending up here in an error regarding this dependency requirement (and not telling me that my package does not support my version of Python).

Output

Case 1 (works as expected):

pip install 'git+https://github.com/gdurif/dummy_pypkg@ok'
Collecting git+https://github.com/gdurif/dummy_pypkg@ok
  Cloning https://github.com/gdurif/dummy_pypkg (to revision ok) to /tmp/pip-req-build-i9sdn066
  Running command git clone --filter=blob:none --quiet https://github.com/gdurif/dummy_pypkg /tmp/pip-req-build-i9sdn066
  Running command git checkout -b ok --track origin/ok
  Switched to a new branch 'ok'
  branch 'ok' set up to track 'origin/ok'.
  Resolved https://github.com/gdurif/dummy_pypkg to commit c9d50124eee91f980031ab42b0a2200bc395e3eb
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
INFO: pip is looking at multiple versions of dummy-pypkg to determine which version is compatible with other requirements. This could take a while.
ERROR: Package 'dummy-pypkg' requires a different Python: 3.13.1 not in '<3.13,>=3.11'

Case 2 (pip does not tell me that my Python version is not supported):

pip install 'git+https://github.com/gdurif/dummy_pypkg@nok'
Collecting git+https://github.com/gdurif/dummy_pypkg@nok
  Cloning https://github.com/gdurif/dummy_pypkg (to revision nok) to /tmp/pip-req-build-yg3vyjub
  Running command git clone --filter=blob:none --quiet https://github.com/gdurif/dummy_pypkg /tmp/pip-req-build-yg3vyjub
  Running command git checkout -b nok --track origin/nok
  Switched to a new branch 'nok'
  branch 'nok' set up to track 'origin/nok'.
  Resolved https://github.com/gdurif/dummy_pypkg to commit 1b8e4d5e5cb3cc5394addfd964f9ee7b031df4ee
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
INFO: pip is looking at multiple versions of dummy-pypkg to determine which version is compatible with other requirements. This could take a while.
ERROR: Could not find a version that satisfies the requirement tensorflow>=2.14.0 (from dummy-pypkg) (from versions: none)
ERROR: No matching distribution found for tensorflow>=2.14.0

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions