uv is an amazing Python package and project manager, well worth trying, especially if you are not tied to other tooling.
Personally, I have been a long-time user of virtualenvwrapper and love its workflow:
- Virtual environments are stored in a dedicated directory (e.g.
~/Envs
). - They are created using
mkvirtualenv ENV_NAME
. - The list of environments can be retrieved with
lsvirtualenv
. - You can activate an environment from anywhere using
workon ENV_NAME
.
However, as far as I can tell, uv
does not support this centralized approach by default. Since I prefer this workflow, I added a few lines to my .zshrc
(they work on .bashrc
too) to replicate the virtualenvwrapper
commands with uv
.
Shell Functions for uv (Linux/macOS)
Simply add these functions to your .zshrc
or .bashrc
:
# virtualenvwrapper commands for uv
function mkvirtualenv {
(cd ~/Envs && uv venv $1)
}
function lsvirtualenv {
ls ~/Envs
}
function workon {
source ~/Envs/$1/bin/activate
}
The only real difference from virtualenvwrapper
is that after activating an environment you should install packages using uv pip
instead of pip
.
Please note that to keep things simple the functions just use the default uv
Python interpreter.
PowerShell equivalent (Windows)
If you’re on Windows, you can achieve the same functionality by adding the following functions to your PowerShell profile:
- Open PowerShell and check your profile path with
echo $PROFILE
. - Open it on your favorite editor (e.g.
notepad $PROFILE
). - Add the following functions:
# virtualenvwrapper commands for uv (PowerShell version)
function mkvirtualenv {
param (
[string]$name
)
Set-Location "$HOME\Envs"
uv venv $name
}
function lsvirtualenv {
Get-ChildItem -Name "$HOME\Envs"
}
function workon {
param (
[string]$name
)
& "$HOME\Envs\$name\Scripts\Activate.ps1"
}
Now you can use the same commands in PowerShell:
mkvirtualenv ENV_NAME
lsvirtualenv
workon ENV_NAME
Final thoughts
If you love the centralized workflow of virtualenvwrapper
, this approach brings the same experience to uv
with minimal changes. It works well on both Linux/macOS and Windows, making it easy to manage virtual environments across platforms.
Enjoy!