# Idea: Specify python version constraints on optional dependencies in a pyproject.toml

**URL:** <https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321>\
**Category:** Packaging\
**Tags:** packaging-help\
**Created:** [October 12, 2025, 2:22am UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321 "2025-10-12T02:22:47Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshdavham](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/joshdavham/32/29661_2.png) [@joshdavham](https://discuss.python.org/u/joshdavham)\
**Post date:** [October 12, 2025, 2:22am UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/1 "2025-10-12T02:22:47Z")

</div>

(Firstly, please do let me know if this is the right place to post this. Thank you!)

So for a bit of background, I maintain a python package that also provides additional optional dependencies for developers who would like some extra features.

The basic python package (without the optional dependencies) is supported on python versions 3.10-3.14. The package is a simple statistical model mainly using the standard library.

Now, the optional dependency allows developers to optimize this model and it depends on torch which is not supported on python 3.14 yet. So my situation currently is that the basic package is supported for python versions 3.10-3.14 while the optional dependencies are only supported on python versions 3.10-3.13.

And unfortunately there doesn’t seem to be a way to specify a python version constraint in the pyproject.toml for the optional dependency.

Are there any plans in the future to allow for the specification of compatible python versions with optional dependencies? Something along the lines of

```python
# pyproject.toml
# (...)

# base dependencies
dependencies = ["typing-extensions"]
requires-python = ">=3.10"

[project.optional-dependencies]
optimizer = ["torch", "pandas"]
requires-python = ">=3.10,<3.14" # <- we can't currently do something like this

# (...)

```

I think this would be a really nice addition!

Please let me know if you have any questions!

(oh and this is the package in question, if anyone’s curious: [GitHub - open-spaced-repetition/py-fsrs: Python Package for FSRS Spaced Repetition](https://github.com/open-spaced-repetition/py-fsrs) .)

---

<div class="post-metadata">

**Author:** ![joshdavham](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/joshdavham/32/29661_2.png) [@joshdavham](https://discuss.python.org/u/joshdavham)\
**Post date:** [October 12, 2025, 6:01am UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/2 "2025-10-12T06:01:16Z")

</div>

Update: there was an attempted solution here [Constrain the `optimizer` extra via markers. by jsirois · Pull Request #143 · open-spaced-repetition/py-fsrs · GitHub](https://github.com/open-spaced-repetition/py-fsrs/pull/143)

I guess what I’m looking for would be for a developer using python 3.14 to encounter a helpful error message when attempting to install the python3.14-incompatible optional dependencies.

---

<div class="post-metadata">

**Author:** ![notatallshaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/notatallshaw/32/10861_2.png) [@notatallshaw](https://discuss.python.org/u/notatallshaw)\
**Post date:** [October 12, 2025, 6:18am UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/3 "2025-10-12T06:18:11Z")

</div>

> [@joshdavham](#):
>
> I guess what I’m looking for would be for a developer using python 3.14 to encounter a helpful error message when attempting to install the python3.14-incompatible optional dependencies.

What’s your original issue? What do users (or yourself) see when they currently select the optional dependencies on Python 3.14?

---

<div class="post-metadata">

**Author:** ![joshdavham](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/joshdavham/32/29661_2.png) [@joshdavham](https://discuss.python.org/u/joshdavham)\
**Post date:** [October 12, 2025, 6:34am UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/4 "2025-10-12T06:34:54Z")

</div>

> What’s your original issue?

I’d like to block python 3.14 users from installing a specific set of optional dependencies instead of them attempting to install it on their own and getting a hard-to-understand error message.

> What do users (or yourself) see when they currently select the optional dependencies on Python 3.14?

They see something like this

```bash
(venv) ➜ py-fsrs git:(main) python --version
Python 3.14.0

(venv) ➜ py-fsrs git:(main) pip install -e ".[optimizer]"
Obtaining file:///Users/joshuahamilton/open-source/py-fsrs
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
INFO: pip is looking at multiple versions of fsrs[optimizer] to determine which version is compatible with other requirements. This could take a while.
ERROR: Could not find a version that satisfies the requirement torch; extra == "optimizer" (from fsrs[optimizer]) (from versions: none)
ERROR: No matching distribution found for torch; extra == "optimizer"

```

The error fundamentally comes from `torch`, _not_ the optional dependency `[optimizer]`. I’d like for there to be an error similar to if you tried to install a regular old package with an incompatible python version.

Hopefully that makes sense?

---

<div class="post-metadata">

**Author:** ![petersuter](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@petersuter](https://discuss.python.org/u/petersuter)\
**Post date:** [October 12, 2025, 8:54am UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/5 "2025-10-12T08:54:21Z")

</div>

Better error messages would be great.

This proposal seems like it would introduce more problems than it solves though, at least in the motivating example. What happens once torch supports Python 3.14? The restriction would still be there and unnecessarily obstruct things.

The error messages should be improved. Introducing more complexity would probably make that more difficult and less likely to actually happen.

---

<div class="post-metadata">

**Author:** ![MegaIng](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/megaing/32/16162_2.png) [@MegaIng](https://discuss.python.org/u/MegaIng)\
**Post date:** [October 12, 2025, 3:07pm UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/6 "2025-10-12T15:07:34Z")

</div>

Upper limits on python versions are a bad idea for 99% of projects; this usecase is one of them. See 100s of messages of previous discussions. (There is a reason e.g. uv just ignores them completely)

Your users just need to learn to read these kinds of error messages and/or pip needs to improve the error messages.

---

<div class="post-metadata">

**Author:** ![notatallshaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/notatallshaw/32/10861_2.png) [@notatallshaw](https://discuss.python.org/u/notatallshaw)\
**Post date:** [October 12, 2025, 5:02pm UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/7 "2025-10-12T17:02:22Z")

</div>

> [@joshdavham](#):
>
> `ERROR: No matching distribution found for torch; extra == "optimizer"`

This part `torch; extra == "optimizer"` comes directly from the [distribution metadata](https://files.pythonhosted.org/packages/2c/4d/a37e29355827576747351455b2979e5e245902cc91a55c265605cf7477fc/fsrs-6.2.0-py3-none-any.whl.metadata), but as you say showing it in this context is misleading, as the extra is referring to the fact that torch is an extra from `fsrs` not for `torch`.

I think at the very least pip should remove this from the installation message so it would be:

> `ERROR: No matching distribution found for torch`

I’ve written up a [pip issue](https://github.com/pypa/pip/issues/13618), please be aware pip is currently an all volunteer project and so requires someone to submit a sufficiently high quality PR to fix. I am working on some Resolution Error messages at the moment but I am unlikely to have time to submit a PR for this.

---

<div class="post-metadata">

**Author:** ![joshdavham](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/joshdavham/32/29661_2.png) [@joshdavham](https://discuss.python.org/u/joshdavham)\
**Post date:** [October 12, 2025, 6:43pm UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/8 "2025-10-12T18:43:25Z")

</div>

> This proposal seems like it would introduce more problems than it solves

Hmm could I get some examples of the problems it would create?

> What happens once torch supports Python 3.14?

Once torch supports python 3.14, I (the maintainer) would loosen the \< 3.14 restriction. I don’t actually think this sounds that bad? It’s the maintainers job to juggle dependencies like this, no?

> The error messages should be improved.

We do on agree on this 🙂

---

<div class="post-metadata">

**Author:** ![joshdavham](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/joshdavham/32/29661_2.png) [@joshdavham](https://discuss.python.org/u/joshdavham)\
**Post date:** [October 12, 2025, 6:44pm UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/9 "2025-10-12T18:44:08Z")

</div>

> Upper limits on python versions are a bad idea for 99% of projects; this usecase is one of them. See 100s of messages of previous discussions.

Might I get a link to one of these 100s of discussions?

---

<div class="post-metadata">

**Author:** ![joshdavham](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/joshdavham/32/29661_2.png) [@joshdavham](https://discuss.python.org/u/joshdavham)\
**Post date:** [October 12, 2025, 6:46pm UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/10 "2025-10-12T18:46:45Z")

</div>

> I think at the very least pip should remove this from the installation message so it would be:
> 
> > `ERROR: No matching distribution found for torch`

I’m no python package genius, but I think a clearer message might be

```python
ERROR: Optional dependency group [optimizer] not supported in Python 3.14

```

I’d prefer for the error to reference the optional dependency group rather than one of that group’s packages (in this case torch).

> I’ve written up a [pip issue](https://github.com/pypa/pip/issues/13618), please be aware pip is currently an all volunteer project and so requires someone to submit a sufficiently high quality PR to fix.

This is appreciated 🙂

And do let me know if you have other questions/arguments, etc.

---

<div class="post-metadata">

**Author:** ![petersuter](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@petersuter](https://discuss.python.org/u/petersuter)\
**Post date:** [October 12, 2025, 7:49pm UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/11 "2025-10-12T19:49:11Z")

</div>

> [@Requires-Python upper limits](https://discuss.python.org/t/requires-python-upper-limits/12663/):
>
> Requires-Python upper limits Requires-Python was added to allow older versions of Python to be dropped by packages without breaking installation on older versions of Python. Currently (and for the last 4+ years), pip handles this quite simply; Requires-Python is a free-form SpecifierSet, and it checks to see if the current version of Python is included in the set. If not, it starts going back through a package’s history to find the most recent passing version. This was prompted by IPython droppi…

> [@Requires-python and pre-release Python versions?](https://discuss.python.org/t/requires-python-and-pre-release-python-versions/62959/):
>
> Currently both pip and uv (and others?) ignore the pre-release section of requires-python. E.g. [project] name = "foo" version = "0.1.0" requires-python = "\>=3.13" [build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build\_meta" Using any Python 3.13 pre-release: $ pip install --dry-run . Processing ... Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Would install foo-0.1.0 Yet t…

---

<div class="post-metadata">

**Author:** ![pf\_moore](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pf_moore/32/35_2.png) [@pf\_moore](https://discuss.python.org/u/pf_moore)\
**Post date:** [October 12, 2025, 8:02pm UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/12 "2025-10-12T20:02:00Z")

</div>

> [@joshdavham](#):
>
> Might I get a link to one of these 100s of discussions?

[Should You Use Upper Bound Version Constraints? -](https://iscinumpy.dev/post/bound-version-constraints/) (this is about upper version constraints in general, but see the section “Pinning the Python version is special” in particular.

Also, see the discussion [Requires-Python upper limits](https://discuss.python.org/t/requires-python-upper-limits/12663) here.

---

<div class="post-metadata">

**Author:** ![notatallshaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/notatallshaw/32/10861_2.png) [@notatallshaw](https://discuss.python.org/u/notatallshaw)\
**Post date:** [October 12, 2025, 9:07pm UTC](https://discuss.python.org/t/idea-specify-python-version-constraints-on-optional-dependencies-in-a-pyproject-toml/104321/13 "2025-10-12T21:07:45Z")

</div>

> [@joshdavham](#):
>
> think a clearer message might be
> 
> ```python
> ERROR: Optional dependency group [optimizer] not supported in Python 3.14
> 
> ```
> 
> I’d prefer for the error to reference the optional dependency group rather than one of that group’s packages (in this case torch).

Currently there is no infrastructure in pip to determine why a distribution could not be found, and the current design of the distribution collector and resolver means it’s not easy to add. So that would be a big feature request.

My understanding is one of the maintainers does have a long term goal of improving the situation and describing why a distribution couldn’t be found. But I’m a strong believer in fixing small things, and at least removing the confusing part of the message, even if doesn’t achieve the long term goal.
