← All fixes
error: externally-managed-environment when running pip install
#139Error
error: externally-managed-environment × This environment is externally managed. To install Python packages system-wide, try apt install python3-xyz (PEP 668, Debian/Ubuntu/Homebrew Python)
Why it happens, and why this works
Since PEP 668, distros and Homebrew mark their Python as externally managed so pip can't overwrite packages the OS depends on. A venv has its own site-packages, so pip installs there without touching the system.
Fix
Install into a virtual environment instead of the system Python. 1. python3 -m venv .venv 2. source .venv/bin/activate (Windows: .venv\Scripts\activate) 3. pip install <package> (now inside .venv) For a standalone CLI tool use pipx install <tool>. Avoid --break-system-packages; it can break the OS's own Python tools.
Did it work?
No reports yet0 worked0 didn't
Known good on: ubuntu@23.04, debian@12, python@3.12
Tried it yourself?
Related fixes
ModuleNotFoundError: No module named 'dotenv' (the pip package is python-dotenv)
#94ModuleNotFoundError: No module named 'dotenv'
pythonVerifiedNo reports yet
ERR_PACKAGE_PATH_NOT_EXPORTED when importing a file deep inside a package
#29Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/helper' is not defined by "exports" in /app/node_modules/mylib/package.json
ModuleNotFoundError: No module named 'bs4' (the pip package is beautifulsoup4)
#97ModuleNotFoundError: No module named 'bs4'
pythonVerifiedNo reports yet