Use `uv init` to lock to a particular Python version
First of all, awesome work uv team! I am really enjoying using uv :)
Background
I have one idea for the uv init command. Take this example:
uv init --app --python 3.12.5
It will generate the following:
[project]
name = "example-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12.5"
dependencies = []
I would like to have a way to specify a specific Python version. E.g. requires-python = "==3.12.5".
[project]
name = "example-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = "==3.12.5"
dependencies = []
Why
Why do I think this would be helpful?
- in
--appmode I am not targeting to support a matrix of Python versions and package versions. I want to deploy my app in the most stable way possible. I should always get the same Python packages (uv.lock handles this) and the same Python version.
Possible solutions
- Support adding version specifiers to uv init. E.g.
uv init --app --python ==3.12.5 - When using
--appmode default to locking in a single version of Python (my guess is that this is what most people want, but I could be wrong!).
Hi! Thanks for the clear description of what you're looking for.
It is specifically not recommended to pin a single Python version in the requires-python field — it's against the intent of the metadata. Instead, you should use uv python pin which creates a .python-version file. We could / should create one of those in uv init. There's a separate issue for storing Python version pins in the pyproject.toml #4970
Thank you @zanieb! I think python pin fits my needs. I also like the idea of storing this in pyproject.toml so there is one less file floating around :)
I also like the idea of creating the .python-version file when uv init is in "app" mode.