# UserWarning：pkg_resources 作为 API 已弃用。参见 https://setuptools.pypa.io/en/latest/pkg_resources.html。pkg_resources 包最早将于 2025-11-30 移除。

- **ID:** `python/setuptools-pkg-resources-deprecated-removed`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

代码（直接或通过依赖）导入了 pkg_resources，setuptools 已弃用该 API 并计划移除。常见于使用 pkg_resources.get_distribution 或 resource_filename 的旧包。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8+ | active | — | — |

## 解决方案

1. **** (92% 成功率)
   ```
   from importlib.metadata import version, distribution
print(version('requests'))

from importlib.resources import files
# replaces pkg_resources.resource_filename
path = files('mypkg').joinpath('data.txt')
   ```
2. **** (80% 成功率)
   ```
   python -W error::DeprecationWarning -c 'import mypkg'  # traceback shows importer
pip install -U <offending-package>  # upgrade to a release using importlib
   ```

## 无效尝试

- **** — Hides the symptom only; the import still executes and will hard-fail once pkg_resources is removed. Also masks the real migration need. (80% 失败率)
- **** — Pins you to an unsupported setuptools, breaks modern build backends, and merely defers the removal. Downstream packages may require newer setuptools. (75% 失败率)
