# 错误：外部管理环境
× 此环境是外部管理的
╰─> 要系统范围内安装 Python 包，请尝试使用 apt install python3-xyz，其中 xyz 是你要安装的包。

如果你想安装非 Debian 打包的 Python 包，请使用 python3 -m venv path/to/venv 创建一个虚拟环境。
然后使用 path/to/venv/bin/python 和 path/to/venv/bin/pip。确保已安装 python3-full。

如果你想安装非 Debian 打包的 Python 应用程序，最简单的方法是使用 pipx install xyz，它会为你管理一个虚拟环境。确保已安装 pipx。

有关更多信息，请参阅 /usr/share/doc/python3.11/README.venv。

- **ID:** `pip/externally-managed-environment-full-message`
- **领域:** pip
- **类别:** config_error
- **错误码:** `error`
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

Python 环境被标记为外部管理（例如，在支持 PEP 668 的 Debian/Ubuntu 系统上），阻止 pip 系统范围安装包，以避免与系统包管理器冲突。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| pip 23.0 | active | — | — |
| pip 23.1 | active | — | — |
| pip 23.2 | active | — | — |
| pip 24.0 | active | — | — |

## 解决方案

1. ```
   创建并使用虚拟环境：'python3 -m venv /path/to/venv'，然后 'source /path/to/venv/bin/activate'，在虚拟环境中安装包。
   ```
2. ```
   使用 pipx 安装 CLI 应用程序：'pipx install <package>'。
   ```

## 无效尝试

- **** — This can break the system Python installation and cause conflicts with apt-managed packages, leading to system instability. (50% 失败率)
- **** — This removes the protection entirely and may cause the same issues as --break-system-packages; also, updates to the python3 package may restore the file. (60% 失败率)
