astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
24.45k stars 708 forks source link

`uv tool install posting` failed with Python version conflict #6381

Open darrenburns opened 2 months ago

darrenburns commented 2 months ago

Firstly, thanks for the amazing work here. This project is incredibly exciting, and I hope the whole community gets onboard.

Earlier today I installed uv (version 0.3.0) using the recommended approach in the docs. I ran uvx posting and received an error roughly along the lines of "the current Python version is 3.10 and posting requires >=3.11, so the constraint could not be satisfied".

This was surprising, as I expected uv to automatically download and install a suitable Python for me (I have not touched any config at all - installing uvx posting was the first thing I tried after installing uv). My understanding was the "current" Python version is irrelevant.

I then ran uv install python 3.11 and repeated uvx posting, and it worked as expected.

I was using an M1 Macbook Pro at the time. I cannot reproduce this issue on a different Intel Macbook Pro.

Unfortunately I don't have access to the machine I encountered this on right now and couldn't report at the time, but can probably add more information soon if required.

charliermarsh commented 2 months ago

Thanks Darren! This is an interesting one. We should probably find a way respect the requires-python of the declared dependencies here (there's a little bit of a chicken-and-egg problem here). Right now, we'd install Python if you did something like uvx --python 3.11 posting, or had a .python-version file in the directory -- but we wouldn't install Python after resolving the dependencies like that. I agree that as a user, you should expect this to work though.

zanieb commented 2 months ago

Ah interesting. We determine the interpreter to use before we resolve the package because we need the markers to perform resolution.

zanieb commented 2 months ago

I guess we could just... download the version and try again with the known requirements instead of failing. I don't think it'd be too slow since it's a rare case.

peppedilillo commented 1 month ago

+1, this is important for me too! i encountered this problem with uv tool install, which I was expecting to install and manage a python instance. Ty for the great work so far!

my1e5 commented 1 week ago

@charliermarsh

Right now, we'd install Python if you did something like uvx --python 3.11 posting, or had a .python-version file in the directory

I think I'm experiencing a bug with this in uv 0.4.21. For me, uvx is not respecting the .python-version file? I've posted a MRE in https://github.com/astral-sh/uv/issues/8206.

But it can be boiled down to the following:

$ uv init --app --package example-packaged-app --python 3.11

$ cd example-packaged-app/

$ uv run example-packaged-app
Using CPython 3.11.4 interpreter at: C:\Users\User\AppData\Local\Programs\Python\Python311\python.exe
Creating virtual environment at: .venv
   Built example-packaged-app @ file:///C:/Users/User/Projects/test/example-packaged-app
Installed 1 package in 16ms
Hello from example-packaged-app!
$ uvx -v --from  file:///C:/Users/User/Projects/test/example-packaged-app  example-packaged-app
DEBUG uv 0.4.21
DEBUG Searching for default Python interpreter in managed installations, system path, or `py` launcher
DEBUG Searching for managed installations at `C:\Users\User\AppData\Roaming\uv\data\python`
DEBUG Found managed installation `cpython-3.13.0-windows-x86_64-none`
DEBUG Found `cpython-3.13.0-windows-x86_64-none` at `C:\Users\User\AppData\Roaming\uv\data\python\cpython-3.13.0-windows-x86_64-none\python.exe` (managed installations)
DEBUG Using request timeout of 30s
DEBUG Found PEP 621 metadata for C:\Users\User\Projects\test\example-packaged-app in `pyproject.toml` (example-packaged-app)
DEBUG Acquired lock for `C:\Users\User\AppData\Roaming\uv\data\tools`
DEBUG Released lock at `C:\Users\User\AppData\Roaming\uv\data\tools\.lock`
DEBUG Caching via interpreter: `C:\Users\User\AppData\Roaming\uv\data\python\cpython-3.13.0-windows-x86_64-none\python.exe`
DEBUG Using request timeout of 30s
DEBUG Found static `pyproject.toml` for: example-packaged-app @ file:///C:/Users/User/Projects/test/example-packaged-app
DEBUG No workspace root found, using project root
DEBUG Solving with installed Python version: 3.13.0
DEBUG Solving with target Python version: >=3.13.0
DEBUG Adding direct dependency: example-packaged-app*
DEBUG Searching for a compatible version of example-packaged-app @ file:///C:/Users/User/Projects/test/example-packaged-app (*)
DEBUG Tried 1 versions: example-packaged-app 1
DEBUG Split specific environment resolution took 0.001s
Resolved 1 package in 4ms
DEBUG Ignoring empty directory
DEBUG Using request timeout of 30s
DEBUG Identified uncached distribution: example-packaged-app @ file:///C:/Users/User/Projects/test/example-packaged-app
DEBUG Acquired lock for `C:\Users\User\AppData\Local\uv\cache\sdists-v4\path\9142387dc7aebe60`
DEBUG Building: example-packaged-app @ file:///C:/Users/User/Projects/test/example-packaged-app
DEBUG Ignoring empty directory
DEBUG Resolving build requirements
DEBUG Solving with installed Python version: 3.13.0
DEBUG Solving with target Python version: >=3.13.0
DEBUG Adding direct dependency: hatchling*
DEBUG Found fresh response for: https://pypi.org/simple/hatchling/
DEBUG Searching for a compatible version of hatchling (*)
DEBUG Selecting: hatchling==1.25.0 [compatible] (hatchling-1.25.0-py3-none-any.whl)
DEBUG Found fresh response for: https://files.pythonhosted.org/packages/0c/8b/90e80904fdc24ce33f6fc6f35ebd2232fe731a8528a22008458cf197bc4d/hatchling-1.25.0-py3-none-any.whl.metadata
DEBUG Adding transitive dependency for hatchling==1.25.0: packaging>=23.2
DEBUG Adding transitive dependency for hatchling==1.25.0: pathspec>=0.10.1
DEBUG Adding transitive dependency for hatchling==1.25.0: pluggy>=1.0.0
DEBUG Adding transitive dependency for hatchling==1.25.0: trove-classifiers*
DEBUG Found fresh response for: https://pypi.org/simple/packaging/
DEBUG Found fresh response for: https://pypi.org/simple/pathspec/
DEBUG Searching for a compatible version of packaging (>=23.2)
DEBUG Selecting: packaging==24.1 [compatible] (packaging-24.1-py3-none-any.whl)
DEBUG Found fresh response for: https://pypi.org/simple/pluggy/
DEBUG Found fresh response for: https://pypi.org/simple/trove-classifiers/
DEBUG Found fresh response for: https://files.pythonhosted.org/packages/08/aa/cc0199a5f0ad350994d660967a8efb233fe0416e4639146c089643407ce6/packaging-24.1-py3-none-any.whl.metadata
DEBUG Found fresh response for: https://files.pythonhosted.org/packages/cc/20/ff623b09d963f88bfde16306a54e12ee5ea43e9b597108672ff3a408aad6/pathspec-0.12.1-py3-none-any.whl.metadata
DEBUG Searching for a compatible version of pathspec (>=0.10.1)
DEBUG Selecting: pathspec==0.12.1 [compatible] (pathspec-0.12.1-py3-none-any.whl)
DEBUG Found fresh response for: https://files.pythonhosted.org/packages/88/5f/e351af9a41f866ac3f1fac4ca0613908d9a41741cfcf2228f4ad853b697d/pluggy-1.5.0-py3-none-any.whl.metadata
DEBUG Searching for a compatible version of pluggy (>=1.0.0)
DEBUG Selecting: pluggy==1.5.0 [compatible] (pluggy-1.5.0-py3-none-any.whl)
DEBUG Searching for a compatible version of trove-classifiers (*)
DEBUG Selecting: trove-classifiers==2024.10.13 [compatible] (trove_classifiers-2024.10.13-py3-none-any.whl)
DEBUG Found fresh response for: https://files.pythonhosted.org/packages/4b/5c/65ae209acac6038f9576893e983b1abcdd6268cab7f5ab124103f4dde701/trove_classifiers-2024.10.13-py3-none-any.whl.metadata
DEBUG Tried 5 versions: hatchling 1, packaging 1, pathspec 1, pluggy 1, trove-classifiers 1
DEBUG Split specific environment resolution took 0.007s
DEBUG Installing in hatchling==1.25.0, packaging==24.1, pathspec==0.12.1, pluggy==1.5.0, trove-classifiers==2024.10.13 in C:\Users\User\AppData\Local\uv\cache\builds-v0\.tmpmfKAzV
DEBUG Requirement already cached: hatchling==1.25.0
DEBUG Requirement already cached: packaging==24.1
DEBUG Requirement already cached: pathspec==0.12.1
DEBUG Requirement already cached: pluggy==1.5.0
DEBUG Requirement already cached: trove-classifiers==2024.10.13
DEBUG Installing build requirements: hatchling==1.25.0, packaging==24.1, pathspec==0.12.1, pluggy==1.5.0, trove-classifiers==2024.10.13
DEBUG Creating PEP 517 build environment
DEBUG Calling `hatchling.build.get_requires_for_build_wheel()`
DEBUG Calling `hatchling.build.build_wheel("C:\\Users\\User\\AppData\\Local\\uv\\cache\\sdists-v4\\path\\9142387dc7aebe60\\w5EB4DN8W0LMM-1ydBKWg\\.tmpkXklQ7", {}, None)`
DEBUG Finished building: example-packaged-app @ file:///C:/Users/User/Projects/test/example-packaged-app
DEBUG Released lock at `C:\Users\User\AppData\Local\uv\cache\sdists-v4\path\9142387dc7aebe60\.lock`
Prepared 1 package in 1.84s
Installed 1 package in 13ms
 + example-packaged-app==0.1.0 (from file:///C:/Users/User/Projects/test/example-packaged-app)
DEBUG Running `example-packaged-app`
DEBUG Looking at `.dist-info` at: C:\Users\User\AppData\Local\uv\cache\archive-v0\h2OOAHfgH4IIxkLSk4BZW\Lib\site-packages\example_packaged_app-0.1.0.dist-info
Hello from example-packaged-app!
DEBUG Command exited with code: 0

Note how it uses Python 3.13.0, even though the .python-version file is 3.11 and a downloaded copy of 3.11 does already exist on my system.