19

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"]

2 Answers 2

23

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"
...
Sign up to request clarification or add additional context in comments.

3 Comments

This is documented packaging.python.org/en/latest/specifications/core-metadata/… but I didn't believe it wouldn't parse requires-python = "3.10" but checking with Ruff beta.ruff.rs/docs confirmed it wouldn't, and it doesn't like "=3.10" either, but "~=3.10" passes.
@NeilG I believe equality should be specified as ==3.10. packaging.python.org/en/latest/specifications/…
Thanks @JonathanHartley :facepalm: - that's why that didn't work then I guess.
3

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

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

2 Comments

"==3.11.1" is simpler. See PEP 508 for the full spec for such strings.
You can find an up-to-date description of dependency specifiers here: packaging.python.org/en/latest/specifications/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.