Clot
Clot

Reputation: 683

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

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?

Upvotes: 39

Views: 61294

Answers (6)

On Linux mint

sudo apt remove pipenv
pip3 install pipenv

or

sudo apt install pipenv

Upvotes: 1

rundekugel
rundekugel

Reputation: 1451

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

Upvotes: 7

KeeVx
KeeVx

Reputation: 11

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

Upvotes: 1

Daniel Braun
Daniel Braun

Reputation: 2712

update pip using code bellow

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10

Upvotes: 33

PaulMcG
PaulMcG

Reputation: 63709

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.

Upvotes: 37

Kelly
Kelly

Reputation: 1

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

Upvotes: -5

Related Questions