Skip to content

uv sync and uv run --no-project end up in different version with same requirements #9514

@ThomasHezard

Description

@ThomasHezard

Hello

I had an issue with torch dependency. I am pretty sure the problem comes from torch and I opened an issue on that matter: pytorch/pytorch#141781

However, while investigating my issue I encountered a uv behaviour I do not fully understand.

The issue can be reproduced with the following very simple pyproject.toml:

[project]
name = "uv-torch-test"
version = "0.1.0"
requires-python = ">=3.8"
dependencies = [
    "torch",
]

If you uv sync with Python 3.8 (either using .python-version or --python 3.8 option), it fails with the following error

error: Distribution `torch==2.5.1 @ registry+https://pypi.org/simple` can't be installed because it doesn't have a source distribution or wheel for the current platform

I think this is expected given the issue described here: pytorch/pytorch#141781.

However, the following command succeeds and indicates that uv ends up installing torch 2.4.1 in this case

uv run --no-project --python 3.8 --with "torch" python -c "import torch; print(torch.__version__)"

In conclusion:

  • One feature request:

    • Having an option to print the package versions in uv run --no-project the same way they are printed in uv sync would have helped me a lot. The only solution to print them today is to use the --verbose option which is extremely verbose. I use a lot the "uv run --no-project" command in my unit testing CI jobs, and adding the --verbose would make the test results and logs difficult to read, whereas I just need the package versions.
  • Two questions:

    • Why does uv run --no-project --python 3.8 --with "torch" dependency resolution ends up choosing 2.4.1 and not 2.5.1 when 2.5.1 is identified as compatible with Python 3.8 by uv sync?
    • Would Introduce a --multi-version preference mode #8686 help avoid this behaviour? (really waiting for this one, it would help on several issues I encountered 😉 )

Thank you 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsking for clarification or support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions