Skip to content

Conversation

@rahuldevikar
Copy link
Contributor

Add PEP 440 version specifier support for --python flag

Implements support for using PEP 440 version specifiers with the --python flag,
allowing users to specify Python versions using operators like >=, <=, ~=, etc.

Examples:

  • virtualenv --python='>=3.12' myenv
  • virtualenv --python='python>=3.11' myenv
  • virtualenv --python='cpython~=3.11.0' myenv

Changes:

  • Added SPECIFIER_PATTERN regex to match version specifiers in py_spec.py
  • Extended PythonSpec to parse and store version_specifier parameter
  • Updated PythonInfo.satisfies() to check version specifier compatibility
  • Made packaging library imports optional with graceful fallback
  • Updated --python help text with version specifier examples
  • Added comprehensive unit and integration tests

Fixes #2994

Use any Python >= 3.12

virtualenv --python=">=3.12" myenv

Use CPython ~= 3.11.0 (compatible release)

virtualenv --python="cpython~=3.11.0" myenv

Use Python between 3.10 and 3.13

virtualenv --python=">=3.10,<=3.13" myenv

With implementation prefix

virtualenv --python="python>=3.11" myenv

@rahuldevikar
Copy link
Contributor Author

rahuldevikar commented Jan 3, 2026

@rahuldevikar rahuldevikar marked this pull request as draft January 3, 2026 06:07
@rahuldevikar rahuldevikar marked this pull request as ready for review January 3, 2026 06:08
@rahuldevikar rahuldevikar force-pushed the users/rahuldevikar/fix2994_clean branch from 4437b46 to 4afaf6c Compare January 3, 2026 06:39
Copy link
Contributor

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is also failing.

@gaborbernat gaborbernat marked this pull request as draft January 5, 2026 14:35
@rahuldevikar rahuldevikar marked this pull request as ready for review January 6, 2026 18:31
@gaborbernat gaborbernat merged commit 0276db6 into pypa:main Jan 7, 2026
51 checks passed
@gaborbernat
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support version specifiers for --python

2 participants