Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
gdurif opened this issue Jan 8, 2025 · 4 comments · May be fixed by #13160
Open
1 task done

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

gdurif opened this issue Jan 8, 2025 · 4 comments · May be fixed by #13160
Labels
C: error messages Improving error messages state: awaiting PR Feature discussed, PR is needed

Comments

@gdurif
Copy link

gdurif commented Jan 8, 2025

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

@gdurif gdurif added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Jan 8, 2025
@notatallshaw notatallshaw added state: awaiting PR Feature discussed, PR is needed C: error messages Improving error messages and removed type: bug A confirmed bug or unintended behavior S: needs triage Issues/PRs that need to be triaged labels Jan 9, 2025
@notatallshaw
Copy link
Member

I could be wrong, but I don't think pip would download any versions of tensorflow, but I agree it's a confusing error message and pip should error out earlier and be clear it's because of the requires-python.

As a side note, for various reasons a lot of tools ignore declared upper bound in the requires-python, e.g. <3.13, and support for it may one day be dropped. But I assume the same behavior is hit with >3.11 and Python 3.11.

@ichard26
Copy link
Member

ichard26 commented Jan 9, 2025

I'm pretty sure this is a duplicate of #11142 which has a resolving PR, but it's stalled. #11398

@gdurif
Copy link
Author

gdurif commented Jan 10, 2025

@notatallshaw If I have other dependencies not raising issue, they will be downloaded before-hand. I modified my dummy package to have an additional requirements:

dependencies = [
    "numpy",
    "tensorflow>=2.14.0"
]

Now, numpy is uselessly downloaded:

pip install --no-cache-dir '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-8bpu8h1x
  Running command git clone --filter=blob:none --quiet https://github.com/gdurif/dummy_pypkg /tmp/pip-req-build-8bpu8h1x
  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 e11b46d87f920febf86e7a7ed40c5fd6d8ff21b3
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting numpy (from dummy-pypkg==0.1.0)
  Downloading numpy-2.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (62 kB)
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: Ignored the following versions that require a different python version: 1.21.2 Requires-Python >=3.7,<3.11; 1.21.3 Requires-Python >=3.7,<3.11; 1.21.4 Requires-Python >=3.7,<3.11; 1.21.5 Requires-Python >=3.7,<3.11; 1.21.6 Requires-Python >=3.7,<3.11; 1.26.0 Requires-Python <3.13,>=3.9; 1.26.1 Requires-Python <3.13,>=3.9
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

EDIT: my bad, only the metadata are downloaded and not the full package....

@gdurif
Copy link
Author

gdurif commented Jan 10, 2025

@ichard26 you are absolutely right, I checked before opening this issue, but I missed it. All my apologies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: error messages Improving error messages state: awaiting PR Feature discussed, PR is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants