On a Windows machine, I'm developing a Python project that I manage using uv
. I run the unit tests with uv run pytest
, and uv
automatically creates a virtual environment in .venv
. So far, so good.
But every now and then, I want to run the unit tests - or other commands - in Linux (from the same project source directory). In my case, this means WSL, but it could also be a VM using a shared folder or a network share. The problem is that the virtual environment is platform specific, so uv run pytest
reports an error that the virtual environment is invalid.
Is it possible to configure uv
to use a different name for the project's virtual environment - e. g., .venv_linux
?
As a workaround, I could move the .venv
folder out of the way and let uv
on Linux create its own .venv
. But I'd have to do that every time I switch between the two, and that would be cumbersome. I also couldn't do this while a command from the project is still running.
To support different virtual environments in a uv-managed project, the environment variable UV_PROJECT_ENVIRONMENT
might be used.
UV_PROJECT_ENVIRONMENT
: Specifies the path to the directory to use for a project virtual environment. See the project documentation for more details.
You could set it to .venv_windows
or .venv_linux
before running uv sync
/ uv run [...]
.