How to fix How to fix 'externally-managed-environment' error in Python (PEP 668) in Python
Modern Python (3.11+) and some Linux distributions prevent pip from installing packages globally to avoid conflicts with system package managers. You must use a virtual environment or install with appropriate flags.
Quick fix
Fixes How to fix 'externally-managed-environment' error in Python (PEP 668)
- Verify the root cause
- Apply the appropriate fix
- Retry the installation
# How to fix 'externally-managed-environment' error in Python (PEP 668)
What this error means
PEP 668 (introduced in Python 3.11 and adopted by Debian/Ubuntu) restricts pip from installing packages to the system Python. This prevents conflicts between pip packages and OS package managers (apt, yum, etc.). The error indicates you are trying to install globally instead of in a virtual environment or with --break-system-packages flag.
Typical symptoms
- pip install fails with 'externally-managed-environment'
- Error message mentions 'PEP 668'
- Works with virtual environment but fails globally
- Appears on Ubuntu 23.04+, Debian 12+, or Python 3.11+
- Running with sudo doesn't help
- Works with older Python versions
- Per-user install (--user) may work as workaround
Common causes
- Installing to system Python instead of virtual environment
- Python or OS enforcing PEP 668 isolation policy
- Using system Python directly (not in venv)
- Package manager locked system Python
- Debian/Ubuntu/Fedora policy preventing global pip installs
- Upgrading to Python 3.11+ or new OS version
- Development environment not set up with virtualenv
How to fix this error
Review the error message above and identify which cause applies to your situation. Run additional diagnostics if needed.
Follow the corresponding solution from the causes section above.
Once you've addressed the root cause, try running 'pip install' again.
Frequently asked questions
- What does "How to fix 'externally-managed-environment' error in Python (PEP 668)" mean?
- 11 and adopted by Debian/Ubuntu) restricts pip from installing packages to the system Python. ). The error indicates you are trying to install globally instead of in a virtual environment or with --break-system-packages flag.
- How do I fix "How to fix 'externally-managed-environment' error in Python (PEP 668)"?
- Modern Python (3.11+) and some Linux distributions prevent pip from installing packages globally to avoid conflicts with system package managers. You must use a virtual environment or install with appropriate flags.
- What causes "How to fix 'externally-managed-environment' error in Python (PEP 668)"?
- Installing to system Python instead of virtual environment Python or OS enforcing PEP 668 isolation policy Using system Python directly (not in venv)
- Is the "How to fix 'externally-managed-environment' error in Python (PEP 668)" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Python Official Documentation
- ๐PEP 668: Excluding system packages(Official Docs)
- ๐ฌSO: externally-managed-environment error(Stack Overflow)
- ๐GitHub: pip issues(GitHub)