17

I am using Python 3.8.7 and the latest version of Pip, v21.0.1. I have written a package that contains the following Python version constraint:

python_requires='>=3.6, <3.9',

When I try to install the package, Pip refuses and prints the following error:

ERROR: Package 'my-package' requires a different Python: 3.8.7 not in '<3.9,>=3.6'

I have seen a similar error when installing other packages with similar version constraints:

ERROR: Package 'my-other-package' requires a different Python: 3.8.7 not in '!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,<3.9,>=2.7'

Clearly Python 3.8.7 is greater than 3.6 and less than 3.9, so why does Pip claim that a different version of Python is required?


Some investigation suggests that this may be an inaccurate error message. I have run an experiment uses packages with the following dependent relationship:

  • package-a requires Python >= 3.6, and depends on package-b;
  • package-b requires Python >= 3.6 and < 3.9.

I have found that when installing package-a using Python 3.9, I receive the following error:

ERROR: Package 'package-a' requires a different Python: 3.9.0 not in '>=3.6'

So basically, package-a cannot be installed with Python 3.9 because package-b does not work with Python 3.9; however, Pip erroneously states that package-a requires a "different" Python, and then erroneously prints out package-a's version specifier, rather than package-b.

I will continue to investigate, but this may be a bug in Pip itself.

mipadi
  • 398,885
  • 90
  • 523
  • 479
  • 1
    I tried to look for examples for how to pass in multiple constraints. It seems to be poorly documented. – astrochun Mar 12 '21 at 02:00
  • It's documented here and as far as I can tell, the specifiers I use follow the guidelines: https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires – mipadi Mar 12 '21 at 02:11
  • I found that documentation, but there's no < example. Should it be <=? Do you need to specify the * afterwards as they did? Do spaces matter after the comma? – astrochun Mar 12 '21 at 02:14
  • Note that in your `my-other-package` you might need to do `!=3.0.*` – astrochun Mar 12 '21 at 02:15
  • 1
    @astrochun: It is, it just got formatted improperly when it was processed as Markdown. – mipadi Mar 12 '21 at 02:18
  • Sorry then. What permutations have you tried? – astrochun Mar 12 '21 at 02:19
  • @astrochun: The version specifiers are documented at https://www.python.org/dev/peps/pep-0440/#version-specifiers. As noted there, "The comma (",") is equivalent to a logical and operator: a candidate version must match all given version clauses in order to match the specifier as a whole. Whitespace between a conditional operator and the following version identifier is optional, as is the whitespace around the commas." – mipadi Mar 12 '21 at 02:20
  • I have, however, tried it both with and without a space after the comma, and with and without a space after the comparison operators, with the same result. – mipadi Mar 12 '21 at 02:21
  • Doubtful this will work, but what if you did `<=3.9`. `< 3.9` should mean up to 3.8.8. – astrochun Mar 12 '21 at 02:27
  • @astrochun: Same thing, except the error message becomes: "ERROR: Package 'my-package' requires a different Python: 3.8.7 not in '<=3.9,>=3.6'" – mipadi Mar 12 '21 at 02:29
  • What about specifying the <3.9 first and then >=3.6? Otherwise I'm out of permutations/ideas. Might be worth reporting it to `setuptools` maintainers. – astrochun Mar 12 '21 at 02:33
  • @astrochun: Same result. – mipadi Mar 12 '21 at 02:36
  • I am having a similar issue https://stackoverflow.com/questions/70307161/why-is-python-using-3-8-1-and-3-9-then-fail-to-install-packages-error-package how did you fix your problem? – Charlie Parker Dec 10 '21 at 15:54
  • I get the error `ERROR: Package pkg requires a different Python: 3.8.1 not in '>=3.9.0'`... bizzare – Charlie Parker Dec 10 '21 at 15:58
  • What is your question? It appears that you already know what the issue is and only point out the incorrect error message. This seems more appropriate as a bug report or feature request, TBH. Perhaps the most recent edit should be a self-answer instead? – MisterMiyagi Dec 10 '21 at 19:40
  • @Charlie Parker why are you surprised that 3.8.1 not >=3.9.0? This error message is actually correct, your Python version is too low. – Lecdi Dec 14 '21 at 08:09
  • Actually, after reading your question it seems you are having a different problem to that of this question. This question is saying that the Python version (correct) is not in the range (incorrect) whereas your problem is that the Python version is not recognised properly... So why have you started a bounty on this question? – Lecdi Dec 14 '21 at 08:20

1 Answers1

11

This was a bug in pip and has been fixed in version 21.1 (see #9541). Specifically, it included the wrong Python constraint (the one of a dependency) in the error message when resolution failed.

a_guest
  • 34,165
  • 12
  • 64
  • 118