python
module_error
ai_generated
true
ImportError:无法从 'packaging.utils' 导入名称 'canonicalize_name'
ImportError: cannot import name 'canonicalize_name' from 'packaging.utils'
ID: python/packaging-utils-import-error
80%修复率
83%置信度
0证据数
2025-12-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
函数 canonicalize_name 在较新版本中已移动到 packaging.utils,但安装的 packaging 库太旧。
English
The function canonicalize_name was moved to packaging.utils in newer versions, but the installed packaging library is too old.
解决方案
-
95% 成功率
pip install --upgrade packaging
-
85% 成功率
try: from packaging.utils import canonicalize_name; except ImportError: from packaging.utils import canonicalize_name as _; # handle manually
无效尝试
常见但无效的做法:
-
40% 失败
Downgrading may break other packages that depend on newer features.
-
80% 失败
The function simply does not exist in older versions; no alternative path works.