'undetected-chromedriver import is unsuccessful. ImportError: cannot import name 'Mapping' from 'collections'

I tried to import undetected_chromedriver

import undetected-chromedriver.v2 as uc

driver = uc.Chrome()

resp = driver.get("https://google.com")

Running above code throws following error.

File "C:\Users\Narmu\Desktop\Python_Workspace_Master\venv\lib\site-packages\undetected_chromedriver\cdp.py"

from collections import Mapping, Sequence
ImportError: cannot import name 'Mapping' from 'collections'

I search for about collections packages but it is not available in package list

I found a suggestion from in VS Code ImportError: cannot import name 'Mapping' from 'collections'?.

But collections.abc also not available in package list.

I use python verion 3.10.

To make this work, kindly suggest me.



Solution 1:[1]

Answer as of 12/11/2021: Don't use Python 3.10. It has bug here and there with undetected_chromedriver package.

I downgraded to 3.7.9 and now all running perfectly fine. You may try other Python version though.

Solution 2:[2]

This has a simple fix - you navigate to your python file -> C:\Users\Narmu\Desktop\Python_Workspace_Master\venv\lib\site-packages\undetected_chromedriver\cdp.py

and update the following line of code -> from collections.abc import Mapping, Sequence

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wildan Gunawan
Solution 2 Abhinav Sinha