使用 pip 安装任何包时,我收到错误无法从集合导入映射?



我在python3.10上工作,我遇到错误,我无法解决。

尝试安装新包或

时显示此错误使用任何pip相关的命令

python 3.10已安装,但无法使用pip添加新包

这个错误如下得到它从命令提示符

C:Program FilesPython310>pip list
Traceback (most recent call last):
File "C:Program FilesPython310librunpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:Program FilesPython310librunpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:Program FilesPython310Scriptspip.exe__main__.py", line 4, in <module>
File "C:UserssaAppDataRoamingPythonPython310site-packagespip__init__.py", line 21, in <module>
from pip._vendor.urllib3.exceptions import DependencyWarning
File "C:UserssaAppDataRoamingPythonPython310site-packagespip_vendorurllib3__init__.py", line 8, in <module>
from .connectionpool import (
File "C:UserssaAppDataRoamingPythonPython310site-packagespip_vendorurllib3connectionpool.py", line 29, in <module>
from .connection import (
File "C:UserssaAppDataRoamingPythonPython310site-packagespip_vendorurllib3connection.py", line 39, in <module>
from .util.ssl_ import (
File "C:UserssaAppDataRoamingPythonPython310site-packagespip_vendorurllib3util__init__.py", line 3, in <module>
from .connection import is_connection_dropped
File "C:UserssaAppDataRoamingPythonPython310site-packagespip_vendorurllib3utilconnection.py", line 3, in <module>
from .wait import wait_for_read
File "C:UserssaAppDataRoamingPythonPython310site-packagespip_vendorurllib3utilwait.py", line 1, in <module>
from .selectors import (
File "C:UserssaAppDataRoamingPythonPython310site-packagespip_vendorurllib3utilselectors.py", line 14, in <module>
from collections import namedtuple, Mapping
ImportError: cannot import name 'Mapping' from 'collections' (C:Program FilesPython310libcollections__init__.py)

那么我该怎么解决这个问题呢?

最后更新的文章

我从路径中删除文件夹urllib3,并执行以下命令重新安装。

但是我得到的错误是

C:UserssaAppDataRoamingPythonPython310site-packagespip_vendor>pip install -U urllib3
Traceback (most recent call last):
File "C:Program FilesPython310librunpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:Program FilesPython310librunpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:Program FilesPython310Scriptspip.exe__main__.py", line 4, in <module>
File "C:UserssaAppDataRoamingPythonPython310site-packagespip__init__.py", line 21, in <module>
from pip._vendor.urllib3.exceptions import DependencyWarning
ModuleNotFoundError: No module named 'pip._vendor.urllib3'

这是collections init.py file

https://pastebin.com/ADc9dV3b

我修改或我将修改的地方

从Python 3.3到3.9,importMappingFromcollections引发一个DeprecationWarning:

DeprecationWarning:使用或从"collections"中导入abc,而不是从"collections"中。abc'自Python 3.3起已弃用,在3.10中它将停止工作

从Python 3.10开始,它不再工作了。看起来您使用的是旧版本的urllib3,因为selector.py文件只存在于1.20、1.21和1.22版本中。当前版本为1.26。

升级urllib3应该能解决这个问题:

[...]# pip install -U urllib3

也许你可以手动删除C:UserssaAppDataRoamingPythonPython310site-packagespip_vendor中的urllib3-X.Y.Z.dist-infourllib3文件夹。然后重新安装urllib3

尝试编辑文件

(C:Program FilesPython310libcollections_init_.py)

和添加到导入

from collections.abc import Mapping

Just add to collections (.abc)获取collections.abc

相关内容

  • 没有找到相关文章

最新更新