Skip to content

Support version specifiers for --python #2994

@FlavioAmurrioCS

Description

@FlavioAmurrioCS

What's the problem this feature will solve?

When doing automation scripts or when trying to create virtualenv for PEP723 scripts, often time I am not aware of the python on the system. Often time I end up doing the following which work most of the times since python is forward compatible for the most part.

export LATEST_PYTHON=${LATEST_PYTHON:-$({ which python3.14 || which python3.13 || which python3.12 || which python3.11 || which python3.10 || which python3.9 || which python3.8 || which python3 } 2>/dev/null)}

virtualenv --python="${LATEST_PYTHON}" venv

When it comes to PEP723 scripts there is a possibility the user can use "~=3.11.0" or "==3.10" or "<=3.9"

Describe the solution you'd like

I would like to be able to run virtualenv --python='>=3.12' venv and have the existing discovery mechanism pick the python for me.

So if a system has python3 , python3.8 and python3.14 it will pick python 3.14 as it is the only one that satisfies the constraint.

Here is the PEP showing the expected behavior https://peps.python.org/pep-0440/#version-specifiers

~=: [Compatible release](https://peps.python.org/pep-0440/#compatible-release) clause
==: [Version matching](https://peps.python.org/pep-0440/#version-matching) clause
!=: [Version exclusion](https://peps.python.org/pep-0440/#version-exclusion) clause
<=, >=: [Inclusive ordered comparison](https://peps.python.org/pep-0440/#inclusive-ordered-comparison) clause
<, >: [Exclusive ordered comparison](https://peps.python.org/pep-0440/#exclusive-ordered-comparison) clause
===: [Arbitrary equality](https://peps.python.org/pep-0440/#arbitrary-equality) clause.

Alternative Solutions

  • Maybe have this be a separate flag ie --python-spec

Additional context

uv it seems to have this feature https://docs.astral.sh/uv/concepts/python-versions/#requesting-a-version

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions