uv icon indicating copy to clipboard operation
uv copied to clipboard

`uv pip` ignores `.python-version` file

Open oliversen opened this issue 1 year ago • 3 comments

Currently, for any uv pip commands, you must explicitly specify the --python-version option. The .python-version file is ignored. Why?

uv 0.5.4 Windows 10

oliversen avatar Dec 02 '24 19:12 oliversen

Can you share the specific uv pip command you're using? We might want different behavior per uv pip command.

Regardless, the goal of the uv pip interface is compatibility with pip which does not read these files. We need a strong justification to differ from the upstream.

zanieb avatar Dec 02 '24 20:12 zanieb

Agreed, I believe this would be a breaking change

samypr100 avatar Dec 03 '24 02:12 samypr100

Can you share the specific uv pip command you're using?

I am using uv in the build of an extension. First, I use the command uv export --only-group bundle -o ./tmp/bundle-reqs.txt. And this command uses the .python-version file. Then I use uv pip install -r ./tmp/bundle-reqs.txt --target ./bundled/libs --python-version 3.9. Here I have to add --python-version 3.9. When I need to change the python version, I will have to change it in two places, which I need to keep in mind. It seems to me that this is not predictable and confusing. Also the fact that uv pip ignores the .python-version file is not mentioned anywhere in the documentation.

oliversen avatar Dec 06 '24 19:12 oliversen

Having a "single source of truth" for the python version in either pyproject.toml or .python-version file isn't currently straightforwardly achievable when using uv pip ... as it is when using native uv ... commands.

It would be nice if for example uv pip compile defaults --python-version if not explicitly given to the value in .python-version file or the requires-python in pyproject.toml.

If it is too tricky or undesirable to untangle with the current default / pip compatibility for the version of the Python interpreter used, then perhaps a new option could be added like --python-version-file similar to how the setup-python action allows? Or perhaps --python-version could accept a filename of pyproject.toml or .python-version as an argument?

ollie-bell avatar Dec 30 '24 14:12 ollie-bell

I can reproduce this issue.

.python-version:

3.12

pyproject.toml

requires-python = ">=3.12"

Result of $ uv python find: /usr/bin/python3.12

The default system python, though, is 3.9: $ command -v python3 -> /usr/bin/python3 and $ python3 --version -> Python 3.9.21.

So uv can definitely find the 3.12 if I ask it to, but here's what's happen with uv pip compile:

$ uv -v pip compile requirements.in
[...]
DEBUG Starting Python discovery for a default Python
DEBUG Looking for exact match for request a default Python
DEBUG Searching for default Python interpreter in virtual environments, managed installations, or search path
DEBUG Searching for managed installations at `/home/renovate/.local/share/uv/python`
DEBUG Found `cpython-3.9.21-linux-x86_64-gnu` at `/usr/bin/python` (first executable in the search path)
DEBUG Using Python 3.9.21 interpreter at /usr/bin/python for builds
DEBUG Using request timeout of 30s
DEBUG Solving with installed Python version: 3.9.21
DEBUG Solving with target Python version: >=3.9.21

The same happens with UV_PYTHON=3.12.

However, if I specify -p directly:

$ uv -v pip compile -p 3.12 requirements.in
[...]
DEBUG Starting Python discovery for Python 3.12
DEBUG Looking for exact match for request Python 3.12
DEBUG Searching for Python 3.12 in virtual environments, managed installations, or search path
DEBUG Searching for managed installations at `/home/renovate/.local/share/uv/python`
DEBUG Found `cpython-3.12.5-linux-x86_64-gnu` at `/usr/bin/python3.12` (first executable in the search path)
DEBUG Using Python 3.12.5 interpreter at /usr/bin/python3.12 for builds
DEBUG Using request timeout of 30s
DEBUG Solving with installed Python version: 3.12.5
DEBUG Solving with target Python version: >=3.12

So not only it ignores .python-version, but also UV_PYTHON.

Edit: using uv 0.5.30

staticf0x avatar Feb 12 '25 13:02 staticf0x

With #11486 we'll respect UV_PYTHON in uv pip compile

zanieb avatar Feb 13 '25 19:02 zanieb

Can confirm with 0.6.0 that UV_PYTHON is honored, but .python-version still isn't.

staticf0x avatar Feb 17 '25 08:02 staticf0x