简体   繁体   English

Python:ImportError: cannot import name 'Mapping' from 'collections' (C:\Program Files\Python310\lib\collections\__init__.py)

[英]Python : ImportError: cannot import name 'Mapping' from 'collections' (C:\Program Files\Python310\lib\collections\__init__.py)

This issue is coming right now.这个问题马上就来了。 why i don't know.为什么我不知道。 But i was not facing this issue before 2 / 3 days.但是我在 2 / 3 天之前没有遇到这个问题。 This error is coming, when my 'import request' starts running.当我的“导入请求”开始运行时,这个错误就来了。 I have tried every single solution on internet but nothing seems to worked.我已经尝试了互联网上的每一个解决方案,但似乎没有任何效果。

"C:\Program Files\Python310\python.exe" "E:/IT Vedant/Rough Work/1mg.py" Traceback (most recent call last): File "E:\IT Vedant\Rough Work\1mg.py", line 2, in import requests File "C:\Program Files\Python310\lib\site-packages\requests_ init _.py", line 58, in from. "C:\Program Files\Python310\python.exe" "E:/IT Vedant/Rough Work/1mg.py" 回溯(最后一次调用):文件 "E:\IT Vedant\Rough Work\1mg.py" ,第 2 行,导入请求文件“C:\Program Files\Python310\lib\site-packages\requests_init _.py ”,第 58 行,来自。 import utils File "C:\Program Files\Python310\lib\site-packages\requests\utils.py", line 26, in from.compat import parse_http_list as parse_list_header File "C:\Program Files\Python310\lib\site-packages\requests\compat.py", line 7, in from.packages import chardet File "C:\Program Files\Python310\lib\site-packages\requests\packages_ init .py", line 3, in from.在 from.compat 中导入 utils 文件“C:\Program Files\Python310\lib\site-packages\requests\utils.py”,第 26 行 import parse_http_list as parse_list_header 文件“C:\Program Files\Python310\lib\site- packages\requests\compat.py",第 7 行,在 from.packages 中 import chardet 文件 "C:\Program Files\ Python310 \lib\site-packages\requests\packages_init .py",第 3 行,在 from。 import urllib3 File "C:\Program Files\Python310\lib\site-packages\requests\packages\urllib3_ init _.py", line 10, in from.connectionpool import ( File "C:\Program Files\Python310\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 38, in from.response import HTTPResponse File "C:\Program Files\Python310\lib\site-packages\requests\packages\urllib3\response.py", line 5, in from. collections import HTTPHeaderDict File "C:\Program Files\Python310\lib\site-packages\requests\packages\urllib3_collections.py", line 1, in from collections import Mapping, MutableMapping ImportError: cannot import name 'Mapping' from 'collections' (C:\Program Files\Python310\lib\collections_ init .py)在 from.connectionpool 导入(文件“C:\Program Files\ Python310 \lib\ site-packages\requests\packages\urllib3\connectionpool.py",第 38 行,在 from.response 中导入 HTTPResponse 文件 "C:\Program Files\Python310\lib\site-packages\requests\packages\urllib3\response.py" ,第 5 行,从collections 导入 HTTPHeaderDict 文件“C:\Program Files\Python310\lib\site-packages\requests\packages\urllib3_collections.py”,第 1 行,从 collections 导入名称映射,MutableMapping 导入错误:不能来自“集合”的“映射”(C:\Program Files\ Python310 \lib\collections_init .py)

Process finished with exit code 1进程以退出代码 1 结束

You are using python 3.10您正在使用 python 3.10

try changing from from collections import Mapping to from collections.abc import Mapping尝试from collections import Mapping更改为from collections.abc import Mapping

in You python 3.10 go to this link在你 python 3.10 go 到这个链接

C:\Program Files\Python310\lib\collections\

and open ficher __init__.py并打开 ficher __init__.py

in this ficher change:在这个 ficher 更改中:

  from collections import Mapping 
 to
 from collections.abc import Mapping

My C:\Program Files\Python310\lib\collections\__init__.py from section didn't seem to have the required entries.我的C:\Program Files\Python310\lib\collections\__init__.py部分似乎没有所需的条目。

To resolve this, I added the following to that file:为了解决这个问题,我在该文件中添加了以下内容:

from collections.abc import Mapping
from collections.abc import MutableMapping
from collections.abc import Sequence

Additionally my project.py file still had the legacy code line import collections which I replaced with the new code line from collections.abc import Mapping此外,我的 project.py 文件仍然具有旧代码行import collections ,我将其替换from collections.abc import Mapping的新代码行

I have the same problem.我也有同样的问题。 I have installed python 3.10.05.我已经安装了 python 3.10.05。 I open the init .py through the IDLE editor, but there is no line like: from collections import Mapping.我通过 IDLE 编辑器打开了init .py,但是没有像:from collections import Mapping 这样的行。 There is import _collections_abs, and from _collections import deque.有 import _collections_abs 和 from _collections import deque。 Would someone have some other solutions.有人会有其他解决方案吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ImportError:无法从“集合”(/usr/lib/python3.10/collections/__init__.py)导入名称“序列” - ImportError: cannot import name 'Sequence' from 'collections' (/usr/lib/python3.10/collections/__init__.py) ImportError:无法从'request'中导入名称'post'(C:\\ Program Files \\ Python37 \\ lib \\ site-packages \\ request \\ __ init__.py) - ImportError: cannot import name 'post' from 'request' (C:\Program Files\Python37\lib\site-packages\request\__init__.py) 导入错误:无法从“distutils”(/usr/lib/python3.8/distutils/__init__.py)导入名称“sysconfig” - ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py) ImportError: 无法从 'urllib' (/usr/lib/python3.7/urllib/__init__.py) 导入名称 'quote' - ImportError: cannot import name 'quote' from 'urllib' (/usr/lib/python3.7/urllib/__init__.py) import MySQLdb报错ImportError: cannot import name '_mysql' from 'MySQLdb' (D:\\python\\lib\\site-packages\\MySQLdb\\__init__.py) - import MySQLdb报错ImportError: cannot import name '_mysql' from 'MySQLdb' (D:\python\lib\site-packages\MySQLdb\__init__.py) ImportError:无法从“变压器”(/usr/local/lib/python3.7/dist-packages/transformers/__init__.py)导入名称“BigBirdTokenizer” - ImportError: cannot import name 'BigBirdTokenizer' from 'transformers' (/usr/local/lib/python3.7/dist-packages/transformers/__init__.py) Python ImportError:无法导入名称__init__.py - Python ImportError: cannot import name __init__.py 导入错误:无法从 'dump' 导入名称 'dump' (~/.local/lib/python3.8/site-packages/dump/__init__.py) - importerror: cannot import name 'dump' from 'dump' (~/.local/lib/python3.8/site-packages/dump/__init__.py) Errno 13 权限被拒绝 'C:\\Program files\\Python310\\CS project.py' - Errno 13 Permission denied 'C:\\Program files\\Python310\\CS project.py' Django2.1.7 导入错误:无法从 'django.forms' (/Users/lib/python3.7/site-packages/django/forms/__init__.py) 导入名称 'util' - Django2.1.7 ImportError: cannot import name 'util' from 'django.forms' (/Users/lib/python3.7/site-packages/django/forms/__init__.py)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM