pip ImportError: cannot import name 'Mapping' from 'collections'
Question:
There appear to be conflicting libraries of python that pip is trying to access, as you can see with the following error:
[root@fedora user]# pip
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pip._internal import main
File "/usr/local/lib/python3.10/site-packages/pip/_internal/__init__.py", line 40, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/main_parser.py", line 12, in <module>
from pip._internal.commands import (
File "/usr/local/lib/python3.10/site-packages/pip/_internal/commands/__init__.py", line 6, in <module>
from pip._internal.commands.completion import CompletionCommand
File "/usr/local/lib/python3.10/site-packages/pip/_internal/commands/completion.py", line 6, in <module>
from pip._internal.cli.base_command import Command
File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 25, in <module>
from pip._internal.index import PackageFinder
File "/usr/local/lib/python3.10/site-packages/pip/_internal/index.py", line 14, in <module>
from pip._vendor import html5lib, requests, six
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/__init__.py", line 25, in <module>
from .html5parser import HTMLParser, parse, parseFragment
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/html5parser.py", line 8, in <module>
from . import _tokenizer
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/_tokenizer.py", line 16, in <module>
from ._trie import Trie
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/_trie/__init__.py", line 3, in <module>
from .py import Trie as PyTrie
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/_trie/py.py", line 6, in <module>
from ._base import Trie as ABCTrie
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/_trie/_base.py", line 3, in <module>
from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib64/python3.10/collections/__init__.py)
How can I fix this to be able to use pip? I have already tried
dnf reinstall python
and dnf reinstall python3
and dnf remove python3-pip, dnf install python3-pip
.
Answers:
I fixed this by removing all pip folders in /usr/local/lib/python3.10/site-packages
Open the File: "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/_trie/_base.py", and at line 3 instead of
from collections import Mapping
add .abc after collections
from collections.abc import Mapping
There appear to be conflicting libraries of python that pip is trying to access, as you can see with the following error:
[root@fedora user]# pip
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pip._internal import main
File "/usr/local/lib/python3.10/site-packages/pip/_internal/__init__.py", line 40, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/main_parser.py", line 12, in <module>
from pip._internal.commands import (
File "/usr/local/lib/python3.10/site-packages/pip/_internal/commands/__init__.py", line 6, in <module>
from pip._internal.commands.completion import CompletionCommand
File "/usr/local/lib/python3.10/site-packages/pip/_internal/commands/completion.py", line 6, in <module>
from pip._internal.cli.base_command import Command
File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 25, in <module>
from pip._internal.index import PackageFinder
File "/usr/local/lib/python3.10/site-packages/pip/_internal/index.py", line 14, in <module>
from pip._vendor import html5lib, requests, six
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/__init__.py", line 25, in <module>
from .html5parser import HTMLParser, parse, parseFragment
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/html5parser.py", line 8, in <module>
from . import _tokenizer
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/_tokenizer.py", line 16, in <module>
from ._trie import Trie
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/_trie/__init__.py", line 3, in <module>
from .py import Trie as PyTrie
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/_trie/py.py", line 6, in <module>
from ._base import Trie as ABCTrie
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/_trie/_base.py", line 3, in <module>
from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib64/python3.10/collections/__init__.py)
How can I fix this to be able to use pip? I have already tried
dnf reinstall python
and dnf reinstall python3
and dnf remove python3-pip, dnf install python3-pip
.
I fixed this by removing all pip folders in /usr/local/lib/python3.10/site-packages
Open the File: "/usr/local/lib/python3.10/site-packages/pip/_vendor/html5lib/_trie/_base.py", and at line 3 instead of
from collections import Mapping
add .abc after collections
from collections.abc import Mapping