Skip to content

Why should I use a virtual environment?

Without a virtual environment, every package you install lands in a single shared directory. One project breaks the moment another installs a different version of a dependency they share. The third time this happens, you stop trusting your own environment.

Why the global install model fails

Four problems compound as the number of projects grows.

  • Version conflicts. Project A needs requests==2.28 and project B needs requests==2.32. You can’t have both installed globally. The last install wins, and the first project starts failing in ways that can take hours to trace back to the cause.

  • Dependency pollution. A shared environment accumulates packages from every project you’ve ever run. When it’s time to deploy or hand a project to a colleague, you can’t reliably list what it actually depends on, only what happens to be installed. Requirements files derived from a polluted environment are guesses, not specifications.

  • System integrity risk. On macOS and Linux, the system Python runs internal OS tools. On Ubuntu, overwriting the system requests library can break apt. The error surfaces weeks later, far from the original cause. (On Windows, the system Python doesn’t run OS tools, but the first two problems still apply.)

  • Reproducibility gaps. Without an isolated environment, you can’t guarantee two machines get the same packages. A colleague’s install resolves to whatever versions happen to be newest that day. Without a clear boundary around a project’s dependencies, a lockfile has nothing stable to capture.

Does uv make this automatic?

uv creates and manages virtual environments without prompting. uv run creates .venv if one doesn’t exist, installs dependencies, and runs the script without a manual activate step. The underlying isolation is the same; uv removes the ceremony.

Even when a tool automates environment management, knowing why virtual environments exist helps when debugging path issues, mixed interpreter versions, or ModuleNotFoundError surprises.

Learn More

Last updated on