python
install_error
ai_generated
true
错误:外部管理环境 × 此环境由外部管理 ╰─> 要系统级安装 Python 包,请尝试 apt install python3-xyz,其中 xyz 是你要安装的包
error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install
ID: python/pip-externally-managed-environment-pep668
80%修复率
90%置信度
0证据数
2024-04-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
PEP 668 通过 EXTERNALLY-MANAGED 标记文件将系统 Python 标记为外部管理。Debian/Ubuntu 和 Homebrew 附带此文件,以防止 pip 破坏操作系统包管理器。
English
PEP 668 marks the system Python as externally managed via an EXTERNALLY-MANAGED marker file. Debian/Ubuntu and Homebrew ship this to prevent pip from breaking the OS package manager.
解决方案
-
98% 成功率
python3 -m venv .venv && source .venv/bin/activate && pip install package
-
95% 成功率
pipx install some-cli-tool
-
90% 成功率
pip install --break-system-packages package
无效尝试
常见但无效的做法:
-
95% 失败
Running as root does not bypass the marker; pip still refuses.
-
40% 失败
Works but breaks the OS package manager's invariants and is reverted on the next apt upgrade.