astral-sh / uv

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

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

Open tleonhardt opened 2 hours ago

tleonhardt commented 2 hours ago

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)
charliermarsh commented 2 hours ago

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

tleonhardt commented 2 hours ago

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!

charliermarsh commented 2 hours ago

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

tleonhardt commented 2 hours ago

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.

zanieb commented 2 hours ago

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.