Attributeerror: Module 'Collections' Has No Attribute 'Mutablemapping'
I Recently Installed Python3.10 on My Ubuntu System and I Believe I Made a Link from /Usr/Bin/Python3 to /Usr/Bin/Python3.10 If I Run Python --Version I Get...
I recently installed python3.10 on my ubuntu system and I believe I made a link from /usr/bin/python3 to /usr/bin/python3.10
If I run python --version I get Python 2.7.17 and if I run python3 --version I get Python 3.10.2
I believe something I did broke something in my global python / pip.
Whenever I try to use pip globally I get this error:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal.cli.main import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 22, in <module>
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 73, in <module>
vendored("pkg_resources")
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 33, in vendored
__import__(modulename, globals(), locals(), level=0)
File "/usr/share/python-wheels/pkg_resources", line 77, in <module>
File "/usr/share/python-wheels/pkg_resources", line 9, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 672, in _load_unlocked
File "<frozen importlib._bootstrap>", line 632, in _load_backward_compatible
File "/usr/share/python-wheels/pkg_resources", line 43, in load_module
File "/usr/share/python-wheels/pkg_resources", line 943, in <module>
AttributeError: module 'collections' has no attribute 'MutableMapping'
After googling I thought the issue is that my pip was made using an older version of python I had so I tried to run:
sudo apt remove python-pip python3-pip
sudo apt install python-pip python3-pip
but even after this I still get the same error with pip.
I do have a virtualenv that I was using with a django project (that uses python 3.10) and if I source into that I am able to use the pip there, but I think this just shows the pip in that venv is properly configured
Result of running ls -la /usr/bin/ | grep -i:
brick@nextgearserver:/etc/apache2$ ls -la /usr/bin/ | grep -i "pip\|python"
lrwxrwxrwx 1 root root 26 Mar 26 2018 dh_pypy -> ../share/dh-python/dh_pypy
-rwxr-xr-x 1 root root 1056 Apr 16 2018 dh_python2
lrwxrwxrwx 1 root root 29 Mar 26 2018 dh_python3 -> ../share/dh-python/dh_python3
lrwxrwxrwx 1 root root 13 Dec 7 2018 lesspipe -> /bin/lesspipe
lrwxrwxrwx 1 root root 23 Feb 27 2021 pdb2.7 -> ../lib/python2.7/pdb.py
lrwxrwxrwx 1 root root 24 Jan 15 13:03 pdb3.10 -> ../lib/python3.10/pdb.py
lrwxrwxrwx 1 root root 23 Dec 8 16:08 pdb3.6 -> ../lib/python3.6/pdb.py
-rwxr-xr-x 1 root root 292 Apr 30 2021 pip
-rwxr-xr-x 1 root root 292 Apr 30 2021 pip2
-rwxr-xr-x 1 root root 293 Apr 30 2021 pip3
lrwxrwxrwx 1 root root 31 Oct 25 2018 py3versions -> ../share/python3/py3versions.py
lrwxrwxrwx 1 root root 26 Mar 26 2018 pybuild -> ../share/dh-python/pybuild
lrwxrwxrwx 1 root root 9 Apr 16 2018 python -> python2.7
lrwxrwxrwx 1 root root 9 Apr 16 2018 python2 -> python2.7
-rwxr-xr-x 1 root root 3633000 Feb 27 2021 python2.7
lrwxrwxrwx 1 root root 33 Feb 27 2021 python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root 16 Apr 16 2018 python2-config -> python2.7-config
lrwxrwxrwx 1 root root 19 Jan 30 15:07 python3 -> /usr/bin/python3.10
-rwxr-xr-x 1 root root 5515256 Jan 15 13:03 python3.10
-rwxr-xr-x 2 root root 4526456 Dec 8 16:08 python3.6
lrwxrwxrwx 1 root root 33 Dec 8 16:08 python3.6-config -> x86_64-linux-gnu-python3.6-config
-rwxr-xr-x 2 root root 4526456 Dec 8 16:08 python3.6m
lrwxrwxrwx 1 root root 34 Dec 8 16:08 python3.6m-config -> x86_64-linux-gnu-python3.6m-config
lrwxrwxrwx 1 root root 16 Oct 25 2018 python3-config -> python3.6-config
-rwxr-xr-x 1 root root 384 Feb 5 2018 python3-futurize
lrwxrwxrwx 1 root root 10 Oct 25 2018 python3m -> python3.6m
lrwxrwxrwx 1 root root 17 Oct 25 2018 python3m-config -> python3.6m-config
-rwxr-xr-x 1 root root 388 Feb 5 2018 python3-pasteurize
-rwxr-xr-x 1 root root 152 Nov 11 2017 python3-pbr
lrwxrwxrwx 1 root root 16 Apr 16 2018 python-config -> python2.7-config
lrwxrwxrwx 1 root root 29 Apr 16 2018 pyversions -> ../share/python/pyversions.py
-rwxr-xr-x 1 root root 2971 Feb 27 2021 x86_64-linux-gnu-python2.7-config
-rwxr-xr-x 1 root root 3246 Jan 15 13:03 x86_64-linux-gnu-python3.10-config
lrwxrwxrwx 1 root root 34 Dec 8 16:08 x86_64-linux-gnu-python3.6-config -> x86_64-linux-gnu-python3.6m-config
-rwxr-xr-x 1 root root 3283 Dec 8 16:08 x86_64-linux-gnu-python3.6m-config
lrwxrwxrwx 1 root root 33 Oct 25 2018 x86_64-linux-gnu-python3-config -> x86_64-linux-gnu-python3.6-config
lrwxrwxrwx 1 root root 34 Oct 25 2018 x86_64-linux-gnu-python3m-config -> x86_64-linux-gnu-python3.6m-config
lrwxrwxrwx 1 root root 33 Apr 16 2018 x86_64-linux-gnu-python-config -> x86_64-linux-gnu
python2.7-config
4 Answers
There are some Libraries aren't fully compatible with 3.10 to the time pf writing this answer
You can downgrade to 3.8 or 3.9 for now and it will work seamlessly
you can find all version for python here
choose your most suitable version
The question already seems to have a solution but for better understanding of the problem, in python 3.10, the attribute MutableMapping from the module collections have been removed.
In your case, /usr/share/python-wheels/pkg_resources uses the MutableMapping attribute of collections.
As a backward compatibility, the attribute has been moved to collections.abc .
So a dirty hack would be to replace all collections.MutableMapping to collections.abc.MutableMapping
An example :
import collections
if sys.version_info.major == 3 and sys.version_info.minor >= 10
from collections.abc import MutableMapping
else
from collections import MutableMapping
just update requests library version to 2.27.1
use :
sudo apt-get install python-requests==2.27.1
In my case, upgrading the following packages worked on Windows 11:
pip install --upgrade pip
pip install --upgrade wheel
pip install --upgrade setuptools
pip install --upgrade requests
I hope this helps