astral-sh / uv

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

uv tool shouldn't use Python from homebrew version directories #7634

Closed frostming closed 2 hours ago

frostming commented 2 hours ago

On a macos machine with homebrew python installed, when installing executables using uv tool install, the base interpreter of the venv points to a python inside homebrew's version directory, for example:

❯ cat '/Users/fming/Library/Application Support/uv/tools/posting/pyvenv.cfg' -p
home = /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/bin
implementation = CPython
uv = 0.2.23
version_info = 3.12.4
include-system-site-packages = false

And the bin/python also symlinks to the same interpreter.

This is subject to breakage when users upgrade the version of python@3.12 formula, because the new intepreter will be in a different directory. It's a huge pain when user run brew upgrade and suddenly all venvs become broken.

To compare, this is what pipx creates:

home = /opt/homebrew/opt/python@3.12/bin
include-system-site-packages = false
version = 3.12.6
executable = /opt/homebrew/Cellar/python@3.12/3.12.6/Frameworks/Python.framework/Versions/3.12/bin/python3.12
command = /opt/homebrew/opt/python@3.12/bin/python3.12 -m venv --without-pip /Users/fming/.local/pipx/venvs/posting
frostming commented 2 hours ago

ok, the issue actually lies in uv venv, where it should not resolve symlinks for the python executable passed in:

$ uv venv .venv -p /opt/homebrew/opt/python@3.12/bin/python3
$ ls -l .venv/bin/python
lrwxr-xr-x  1 fming  staff    96B  9 23 11:56 .venv/bin/python -> /opt/homebrew/Cellar/python@3.12/3.12.6/Frameworks/Python.framework/Versions/3.12/bin/python3.12
zanieb commented 2 hours ago

I believe this is a duplicate of https://github.com/astral-sh/uv/issues/1640

zanieb commented 2 hours ago

And yeah, sorry this sounds painful.

frostming commented 2 hours ago

Yeah, that is duplicate. Closing this now.