Skip to content

Warn when .python-version conflicts with uv venv -p <version> in projects #8847

Description

@tleonhardt

Summary

I ask uv to install a Python 3.12 virtual environment and then ask it to run a command using what I assume is the default virtual environment and it actually runs it using Python 3.13.

Perhaps I am misunderstanding how uv is supposed to work but this is a very non-intuitive customer experience.

How to reproduce

$ uv venv --python 3.12
Using CPython 3.12.6
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
$ uv run python -V
Using CPython 3.13.0
Removed virtual environment at: .venv
Creating virtual environment at: .venv
...

Platform details

$  uv --version
uv 0.4.30 (Homebrew 2024-11-05)
  • OS: macOS Sequoia 15.1 (Apple Silicon)

Activity

  1. charliermarsh commented on Nov 5, 2024

    @charliermarsh
    Member

    Do you have a .python-version file in the directory that pins to 3.13, maybe?

  2. tleonhardt commented on Nov 5, 2024

    @tleonhardt
    Author

    Doh! I do have a .python-version file in that directory pinned to 3.13. I'm not sure where it came from.

    I removed it and now it works as expected.

    @charliermarsh You are the best. Your response time is truly insane. Thank you sir!

  3. charliermarsh commented on Nov 5, 2024

    @charliermarsh
    Member

    Really glad I could help! (I wonder if we should've warned in the first uv venv invocation? \cc @zanieb)

  4. tleonhardt commented on Nov 5, 2024

    @tleonhardt
    Author

    I view this as 100% my own fault.

    But if you could warn users to let them know about this potentially unanticipated behavior, that would be fantastic.

  5. zanieb commented on Nov 5, 2024

    @zanieb
    Member

    Thanks for the ping, yeah it seems like we should probably warn there if you're changing to virtual environment to something we won't use in future project invocations.

    uv run should also say where it sourced that version from. I might have made that easier in #6370.

  6. self-assigned this
    on Nov 5, 2024
  7. reopened this on Nov 5, 2024
  8. changed the title [-][Bug?] uv venv --python 3.12 creates a Python 3.13.0 virtual environment[/-] [+]Warn when `.python-version` conflicts with `uv venv -p <version>` in projects[/+] on Nov 5, 2024
  9. Belval commented on May 8, 2025

    @Belval

    Any update on this? We encountered a situation where it delete a .venv that took some time to install...

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions