37

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?

Aditya Yadav
  • 607
  • 1
  • 5
  • 15

6 Answers6

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.

PaulMcG
  • 62,419
  • 16
  • 94
  • 130
32

update pip using code bellow

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
Daniel Braun
  • 2,452
  • 27
  • 25
  • 3
    You may need to do: `sudo apt-get install python3.10-distutils` if you get the error: `ModuleNotFoundError: No module named 'distutils.cmd'` – Suhail Doshi Jun 28 '22 at 00:00
1

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

Peter Trcka
  • 1,279
  • 1
  • 16
  • 21
KeeVx
  • 11
  • 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](/help/how-to-answer). – Community Mar 07 '22 at 16:12
1

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

rundekugel
  • 1,118
  • 1
  • 10
  • 23
0

On Linux mint

sudo apt remove pipenv
pip3 install pipenv

or

sudo apt install pipenv
moken
  • 3,227
  • 8
  • 13
  • 23
-5

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

Kelly
  • 1
  • 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. – Kelly Oct 12 '21 at 04:35
  • 1
    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](/help/how-to-answer). – R. Marolahy Oct 12 '21 at 05:24