uv: find_uv_bin fails to find uv when already inside a virtualenv
I am inside a virtualenv that was created using mise and uv where uv is installed
Code to reproduce:
❯ echo $VIRTUAL_ENV
/Users/ssbarnea/.venv
❯ which python3
/Users/ssbarnea/.venv/bin/python3
❯ which uv
/Users/ssbarnea/.config/mise/installs/python/3.13.0/bin/uv
❯ python3 -c "from uv._find_uv import find_uv_bin; print(find_uv_bin())"
Traceback (most recent call last):
File "<string>", line 1, in <module>
from uv._find_uv import find_uv_bin; print(find_uv_bin())
~~~~~~~~~~~^^
File "/Users/ssbarnea/.config/mise/installs/python/3.13.0/lib/python3.13/site-packages/uv/_find_uv.py", line 37, in find_uv_bin
raise FileNotFoundError(path)
FileNotFoundError: /Users/ssbarnea/.local/bin/uv
That is breaking tox-uv plugin which needs this functionality. I think that fixing this should be quite easy and I will try to propose a patch.
I should mention that in this case the venv was created with use system packages option, and probably this is why uv module is present but fails to find its own script (executable in our case), because that script is not inside the venv own script directory but it is inside system python script directory.
In fact if find_uv_bin implementation would have used shutil.which to find the executable it would have worked.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 18 (8 by maintainers)
Commits related to this issue
- Fix find_uv_bin to find uv with system site packages Fixes: #10194 — committed to ssbarnea/uv by ssbarnea 2 years ago
I think both the code and the error is not complete. It tries several paths and then reports FileNotFound for the first. Shouldn’t it report all paths?
Also:
target_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "bin", uv_exe)can’t be correct, can it?__file__is<prefix>/lib/python3.13/site-packages/uv/_find_uv.py. So there are about 3 levels ofdirnamemissing, aren’t there?