# DeprecationWarning: pkg_resources 作为 API 已被弃用。参见 https://setuptools.pypa.io/en/latest/pkg_resources.html
UserWarning: pkg_resources 作为 API 已被弃用。

- **ID:** `python/setuptools-pkg-resources-deprecation-error`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

代码或依赖导入了 `pkg_resources`，setuptools 已弃用它，推荐改用 `importlib.metadata` 和 `importlib.resources`；在 `-W error` 下会变成硬错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Migrate imports: replace `import pkg_resources; pkg_resources.get_distribution('x').version` with `from importlib.metadata import version; version('x')`.
   ```
2. **** (70% 成功率)
   ```
   If the warning comes from a dependency, pin a fixed version or open an issue; locally silence only that line with `warnings.filterwarnings('ignore', category=UserWarning, module='pkg_resources')`.
   ```

## 无效尝试

- **** — Only postpones the removal; newer deps require modern setuptools. (70% 失败率)
- **** — Hides real issues and the API may be removed in a future release. (50% 失败率)
