Getting AttributeError: module 'collections' has no attribute 'MutableMapping' while using any pip3 command on linux Python 3.10
Asked Answered
M

6

38

Hey I have installed latest python 3.10 and pip3 on my linux (Zorin os lite 15.3 X64) machine but whenever I try to use any pip3 command I get following error For example I use the command:

pip3 freeze

I get the following error:

Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip 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-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 77, in <module>
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/_vendor/packaging/requirements.py", 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-0.0.0-py2.py3-none-any.whl/pkg_resources/extern/__init__.py", line 43, in load_module
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/_vendor/pyparsing.py", line 943, in <module>
AttributeError: module 'collections' has no attribute 'MutableMapping'

This was working fine with python 3.9 but when I updated to 3.10 I started getting this error. How can I solve this?

Mesocratic answered 10/10, 2021 at 5:51 Comment(3)
Were you able to finally resolve this for yourself? Updating Python to 3.10.1 did not help.Cardoon
No, I switched back to version 3.9Mesocratic
Please see update below - I think we have a solution (or at least a workaround).Cardoon
C
37

The problem is caused by an old version of pyparsing that has been vendored into pkg_resources, which is now part of setuptools.

I think if you install an updated setuptools, things will run better:

python -m pip install -U setuptools

EDIT - After installing my own version of 3.10.1 on Ubuntu 18.04, I am having this same issue. And the broken pkg_resources is preventing doing any updates, so your classic Catch-22. To begin chasing down a resolution, I've submitted a ticket on the setuptools Github repo.

EDIT2 - Based on aid on the setuptools GitHub repo, I did the following steps:

# add deadsnake repo (default or nightly)
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10
git clone https://github.com/pypa/setuptools.git && cd setuptools && sudo python3.10 setup.py install
sudo apt install python3.10-distutils
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
sudo apt install python3.10-venv

At this point, I am able to run pip in Python3.10, and create venvs using python3.10 -m venv virtualenv-dir.

Cardoon answered 14/10, 2021 at 15:24 Comment(9)
Did this work for anyone? I am using python 3.10 installed via pyenv, and it did not work for me. I am also using pipenv in my enviroment if that makes a difference.Originative
pkg_resources imports packaging, which imports pyparsing. The pyparsing 3.0.5 release included breaking API changes, which were refactored back in in pyparsing 3.0.6. If still not working after updating to pyparsing 3.0.6, please post an issue on pyparsing's GitHub.Cardoon
Packaging 21.3 just got pushed to pypi, compatible with the latest pyparsing, so I think these issues should all be sorted if upgrade to latest of both packages.Cardoon
@AugustineCalvino - I am seeing this issue now on Ubuntu, working on it. Were you able to resolve?Cardoon
No, I was not able to resolve this - I ended up switching to Poetry for this and a few other reasons.Originative
It work for my case. Ubuntu 16.04 and python3.10.Retriever
Solves the error for python3.10 on Ubuntu18Friedly
solve the error after updating python3.6 to python3.10 on bionicDamales
This worked for me under WSL Ubuntu-18.04 .Sissified
T
32

update pip using code bellow

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
Trimble answered 23/2, 2022 at 11:4 Comment(1)
You may need to do: sudo apt-get install python3.10-distutils if you get the error: ModuleNotFoundError: No module named 'distutils.cmd'Expound
A
6

"Do not install pipenv from apt, it's way too old. Install from pypi." source: https://github.com/pypa/pipenv/issues/5469

This solve it for me:

sudo apt remove pipenv
pip install pipenv

Unfortunately pipenvdidn't worked out of the box in this console. I had to use:

python -m pipenv

Or simply start a new terminal session.

Agle answered 21/4, 2023 at 7:2 Comment(0)
D
1

I can try to fix it with pip install request --upgrade

Danby answered 7/3, 2022 at 15:31 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Pilfer
B
1

On Linux mint

sudo apt remove pipenv
pip3 install pipenv

or

sudo apt install pipenv
Bussy answered 11/8, 2023 at 12:27 Comment(0)
A
-5

Update pip...collections.MutableMapping has become collections.abc.MutableMapping.

Armhole answered 12/10, 2021 at 4:33 Comment(2)
Actually you want to update python wheel. If you run into any other issues, the first thing to do is to update to the latest package versions from pypi.Armhole
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Maclean

© 2022 - 2024 — McMap. All rights reserved.