Should `uv run` always create a virtual environment?
I think yes, if one cannot be found. Otherwise, a command can mutate the system environment (e.g. uv run pip install anyio).
Interesting, so like, never run in the base env?
Maybe? It seems okay to run in virtual or project environments, but weird for non-virtual environments.
I feel like uv creates virtual environments so quickly that it might not be a big deal to always create a virtual environment.
Does that seem like a good default behavior? Lately the python dev community has shifted in the direction of isolating as much as possible, whenever possible.
Not entirely sure about this. I see it as whether or not the base env (I call it global env) is still necessary.
uv tool[^1] has remove a lot of the need for base env, but I think there are a few key use cases that pipx historically do not support.
A motivating example would be Jupyter where many users treat it as a global tool not belonging to any particular environment. How does uv run jupyter work here?
[^1]: huh, I just learned about uvx. What's the difference? Both seems like pipx replacement.
uv run jupyter will fail unless you're in a project that requires jupyter or it is otherwise installed on your system, e.g., in the environment of the interpreter that uv finds. uvx jupyter will install and run jupyter in an isolated environment. There's some documentation on this.
We can't really get around the base environment. It can be immutable, but we're a Python package tool and we need a Python interpreter for most operations. uv run will probably always find a Python interpreter. The question is if we should force you to be isolated from that base environment by creating an empty virtual environment.
Sounds good to me.
Is the venv created at some temporary directory (current behavior for uv run example.py)?
That would be the idea, yeah. Though for uv run example.py I think we'll re-use a cached environment.