11

Setuptools allows you to specify the minimum python version as such:

from setuptools import setup

[...]

setup(name="my_package_name",
      python_requires='>3.5.2',
      [...]

However, how can you do this with the pyproject.toml? The following two things did NOT work:

[project]
...
# ERROR: invalid key 
python_requires = ">=3"

# ERROR: no matching distribution found
dependencies = ["python>=3"]
gebbissimo
  • 2,137
  • 2
  • 25
  • 35

2 Answers2

15

According to PEP 621, the equivalent field in the [project] table is requires-python.

More information about the list of valid configuration fields can be found in: https://packaging.python.org/en/latest/specifications/declaring-project-metadata/.

The equivalent pyproject.toml of your example would be:

[project]
name = "my_package_name"
requires-python = ">3.5.2"
...
  • This is documented https://packaging.python.org/en/latest/specifications/core-metadata/#requires-python but I didn't believe it wouldn't parse `requires-python = "3.10"` but checking with Ruff https://beta.ruff.rs/docs/ confirmed it wouldn't, and it doesn't like `"=3.10"` either, but `"~=3.10"` passes. – NeilG Aug 18 '23 at 15:56
0

To force the use of an exact micro-version of CPython, use the syntax:

requires-python = ">=3.11.1,<3.11.2"

cclauss
  • 552
  • 6
  • 17