python 3.12 报 module 'pkgutil' has no attribute 'ImpImporter'
在 Python 3.12 中,使用较低版本的 pip(如 22.3.1)安装包时,可能会遇到错误 module 'pkgutil' has no attribute 'ImpImporter'。这是因为 pkgutil.ImpImporter 在 Python 3.3 中已被标记为废弃,并在 Python 3.12 中被移除。以下是解决此问题的方法:
解决步骤
- 升级 pip 到最新版本 使用以下命令升级 pip:
或者
- 重新安装 Manim 升级 pip 后,再次尝试安装 Manim:
- 处理 setuptools 问题 如果在安装过程中,setuptools (65.5.0) 版本也出现同样的异常,可以按照以下步骤处理:
- 使用管理员身份运行 PowerShell
-
卸载 setuptools:
-
重新安装 setuptools:
-
再次运行 Manim 的安装命令:
参考链接
- python - No module named pkg_resources - Stack Overflow
- AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'? · Issue #108541 · python/cpython (github.com)
- pip's vendored pkg_resources should stop using pkgutil.ImpImporter · Issue #11501 · pypa/pip (github.com)
- https://segmentfault.com/a/1190000044275585
通过以上步骤,可以解决在 Python 3.12 中因 pkgutil.ImpImporter 被移除而导致的安装问题。