Python3.11执行pip install pyinstaller时触发ImportError错误求助
解决pip安装PyInstaller时出现的
ImportError: cannot import name 'Mapping' from 'collections'错误 错误根源
你的Python 3.11环境中,pip依赖的html5lib版本过旧——它尝试从collections模块导入Mapping类,但该类在Python 3.10及以上版本已迁移至collections.abc模块,导致导入失败。
解决方案
方案一:升级pip到最新版本
执行以下命令,自动更新pip及其依赖的所有兼容库:
python -m pip install --upgrade pip
方案二:手动修复html5lib的导入问题(方案一失效时使用)
找到报错路径对应的文件:C:\Users\JUAN ANDRES TELLEZ V\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pip\_vendor\html5lib\_trie\_base.py
打开文件后,将第3行的:
from collections import Mapping
修改为:
from collections.abc import Mapping
方案三:用内置工具重新安装pip
执行命令彻底重置并升级pip:
python -m ensurepip --upgrade
完成上述任一操作后,重新执行pip install pyinstaller即可正常安装。
内容的提问来源于stack exchange,提问作者JUAN ANDRES TELLEZ VANEGAS
相关产品推荐
相关产品推荐

