Fix Python Dependency Hell & Broken Virtual Environments
Why global pip install breaks system Python (externally-managed-environment) and how venv, uv, and lockfiles keep projects clean.
By the end of this tutorial you will know:
- Why modern Linux/macOS blocks global
pip installwithexternally-managed-environment - How to isolate every project with
python3 -m venvoruv - How to freeze exact versions so teammates get the same packages
Prerequisites: Python 3.10+ installed.
1. The big idea
Your operating system uses Python internally for system tools. If you run pip install globally, you risk overwriting a library version that your OS depends on. That is why Ubuntu 24.04+, Debian 12+, and Homebrew now stop you with:
error: externally-managed-environmentA virtual environment is simply a project-local folder (.venv) with its own python and pip, completely isolated from the rest of your machine.
2. The fix: create and activate .venv
Inside your project directory:
python3 -m venv .venv
source .venv/bin/activateOn Windows PowerShell:
.\.venv\Scripts\Activate.ps1Now check which Python is active:
which python/home/you/my-project/.venv/bin/pythonInstall packages safely inside .venv, and save a lockfile:
pip install httpx
pip freeze > requirements.txtOr use uv for near-instant environment creation and lockfiles:
uv init
uv add httpxRun python -m pip list inside your activated .venv. You should see only the packages installed for this project, not dozens of system packages.
3. Common pitfalls
| Mistake | Symptom | Fix |
|---|---|---|
Running pip install --break-system-packages | Breaks OS scripts after upgrades | Use .venv or pipx for CLI tools |
Forgetting source .venv/bin/activate | ModuleNotFoundError for installed packages | Activate .venv or run .venv/bin/python directly |
Committing .venv/ to Git | Massive PRs and broken OS binaries | Add .venv/ to .gitignore |
4. What you learned
You now know why global pip fails on modern systems and how isolating every project with .venv or uv + lockfiles prevents dependency conflicts.