uv
uv copied to clipboard
Enhancement Request: `uv pip install` with explicit venv path
Thanks for uv, it's very impressive! :)
Our build system creates and manages a virtual environment that's used for later parts of the build, and to host editably-installed packages that have console script entry points.
To remove complexity (environment variables, python versions, PATH shenanigans) and potential ambiguity, we try to avoid modally entering the virtual environment via activate, and instead invoke pip via the venv's python:
/path/to/my/venv/bin/python -m pip ...
(We do this on mac/linux and also windows, but I'm just using the non-windows forms here)
Right now, uv pip seems to require running inside of a modally-activated venv. It would be very handy if we could give uv pip an explicit path to the virtual environment directory, similar to how uv venv can be given an explicit python interpreter.
Hi! Thank you :)
You can provide the virtual environment path via the VIRTUAL_ENV variable or, if you run python -m uv, we'll automatically detect the virtual environment (#1504).
We may consider adding this as a CLI option too, I think there are a couple other similar issues about that.
Thanks for the quick response, and sorry I missed the VIRTUAL_ENV variable; if I can set that before spawning uv that'll totally work for us. :)
python -m uv is interesting and I think even nicer; would it be interesting to have an option like --seed for uv venv that also installed uv into the new venv? That would handle bootstrapping pretty elegantly, I think.
Hm yeah it seems like we should probably stub uv into the environment by default so that you can use python -m uv. I'm not exactly sure what that would look like.
If the Python uv package uses uv functionality by bundling the executable, it might be nice to have a venv-creation bootstrap copy-in the uv executable that invoked the venv command. That would be nice for pinning versions etc; for a single-file executable like this, we'd version it by just checking it into git.
Tracking that in https://github.com/astral-sh/uv/issues/1632
Ah and here's the other one for the CLI option, going to close this in favor of those https://github.com/astral-sh/uv/issues/1396