简体   繁体   中英

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. 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. 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. 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)

Process finished with exit code 1

You are using python 3.10

try changing from from collections import Mapping to from collections.abc import Mapping

in You python 3.10 go to this link

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

and open ficher __init__.py

in this ficher change:

  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.

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

I have the same problem. I have installed python 3.10.05. I open the init .py through the IDLE editor, but there is no line like: from collections import Mapping. There is import _collections_abs, and from _collections import deque. Would someone have some other solutions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM