Sub topic 14
Where virtualenv, pipx, and uv fit
This chapter assumes you can create and activate an environment with python -m venv, install packages with python -m pip, and read a requirements file. It places three related tools next to those two. You don't need any of them to follow the rest of the tutorial.
The shared idea
Each tool builds on the same mechanism: a directory with its own interpreter entry point and its own site-packages. They differ in who creates that directory, how fast they do it, and what job they target.
virtualenv
virtualenv is a third-party package that predates venv and inspired it. It does the same job, so the environment layout and activation scripts look familiar. It is usually faster because it caches the wheels used to seed new environments. It can also target a different installed Python by name.
python3 -m pip install virtualenv
python3 -m virtualenv .venv
source .venv/bin/activate
python -m pip --version
deactivateChoose it when you need those extras, or when a tool such as tox already uses it. For a plain project, venv is enough, and it needs no install.
pipx
pipx installs command-line applications, not libraries you import. Each application gets its own environment, and pipx puts only its executables on your PATH. This keeps tools like black or httpie from conflicting with your project dependencies or with each other.
python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install black
pipx list
pipx upgrade black
pipx run cowsay -t "hello"
pipx uninstall blackpipx run downloads a tool into a temporary environment and runs it once. Don't use pipx for a project's own dependencies. Those belong in the project's environment so the requirements file describes them.
uv
uv is a single fast program, written in Rust, from Astral. It replaces several tools. Its uv pip interface mimics common pip commands, so existing requirements files work unchanged.
uv venv .venv
source .venv/bin/activate
uv pip install -r requirements.txt
uv pip listIt also has a project workflow that manages pyproject.toml and a lock file for you, and a uv tool command that plays the role of pipx.
uv init demo
cd demo
uv add requests
uv run python -c "import requests; print(requests.__version__)"
uv tool install blackuv venv does not put pip inside the new environment unless you ask for it with --seed. Inside such an environment, python -m pip fails with "No module named pip". Use uv pip install instead, or create the environment with uv venv --seed.
Choosing between them
| Situation | Reasonable choice |
|---|---|
| Learning, small scripts, CI with no extra installs | `venv` and `pip` |
| Many environments, or a specific Python version by name | `virtualenv` or `uv` |
| Installing a developer tool for daily use | `pipx` or `uv tool` |
| Large dependency sets where install time hurts | `uv` |
Exercise
You run uv venv .venv, activate it, and then python -m pip install requests fails with "No module named pip". Why, and what are two ways to fix it?
Show answer
uv venv creates the environment without seeding pip. Either install with uv pip install requests, or recreate the environment with uv venv --seed .venv so pip is included.