# 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](https://pydevtools.com/handbook/explanation/what-is-a-lock-file.md) has nothing stable to capture.

## Does uv make this automatic?

[uv](https://pydevtools.com/handbook/reference/uv.md) 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

- [What is a Virtual Environment?](https://pydevtools.com/handbook/explanation/what-is-a-virtual-environment.md) covers the mechanics: how activation works and what isolation looks like in a real terminal session
- [Why should I avoid using the system Python?](https://pydevtools.com/handbook/explanation/why-should-i-avoid-system-python.md) covers the related risk of installing packages into the system interpreter
- [venv](https://pydevtools.com/handbook/reference/venv.md) reference
- [virtualenv](https://pydevtools.com/handbook/reference/virtualenv.md) reference
- [How to create and use a Python virtual environment with venv](https://pydevtools.com/handbook/how-to/how-to-create-and-use-a-python-virtual-environment-with-venv.md)
