Pip Can't Install package or show package after Upgrade to Python 3.10 from 3.6

I try to upgrade from Python 3.6 to 3.10 then pip can’t list packages nor install any package.

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
apt list | grep python3.10
sudo apt-get install python3.10

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2

 sudo update-alternatives --config python3

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

I put this on my .bashrc:

alias pip310='python3.10 -m pip'

When I type pip310 list, get error:

Keyring is skipped due to an exception: module 'collections' has no attribute 'MutableMapping'
ERROR: Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/cli/base_command.py", line 167, in exc_logging_wrapper
    status = run_func(*args)
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/commands/list.py", line 166, in run
    for d in get_environment(options.path).iter_installed_distributions(
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/metadata/__init__.py", line 85, in get_environment
    return select_backend().Environment.from_paths(paths)
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/metadata/__init__.py", line 63, in select_backend
    from . import pkg_resources
  File "/usr/local/lib/python3.10/dist-packages/pip/_internal/metadata/pkg_resources.py", line 8, in <module>
    from pip._vendor import pkg_resources
  File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3252, in <module>
    def _initialize_master_working_set():
  File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3235, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3277, in _initialize_master_working_set
  File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3278, in <genexpr>
  File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2785, in activate
  File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2284, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2217, in _handle_ns
  File "/usr/lib/python3/dist-packages/mpl_toolkits/__init__.py", line 2, in <module>
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 77, in <module>
  File "/usr/lib/python3/dist-packages/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
    from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
  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/lib/python3/dist-packages/pkg_resources/extern/__init__.py", line 43, in load_module
  File "/usr/lib/python3/dist-packages/pkg_resources/_vendor/pyparsing.py", line 943, in <module>
AttributeError: module 'collections' has no attribute 'MutableMapping'

Another question: How to Uninstall the previous Python 3.6? So I only have Python 3.10

Capture d’écran_2022-08-03_13-37-54

Do not replace your system Python with a different version. When you do this multiple tools can stop working.

Simply do not use update-alternatives to swich what python3 points to and call your Python 3.10 using command python3.10. In your case switch python3 back to python3.6.

Also it could be that in Debian and derived systems you have to install pip as a separate package: sudo apt install python3.10-pip. (Though I am not sure.)

1 Like

@vbrozik I know…

it is a regret to change my Python’s system.
Why Python is like this?

Anyway, I want to know how to delete python3.10 that is already installed, should I delete it manually?

I want to revert to use Python 3.6 again, and I can use higher Python version in conda inside Julia. I use python 3.10 there without any hassle.

This may or may not be of help: if you’re using the ‘Timeshift’ System Restore Utility, it may be wise to simply restore to a point before you did what you did.

Normally switching back to the original python version using sudo update-alternatives should fix the system. But I am afraid this command could have really messed up your system (I did not notice it earlier):

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

If you want to investigate, you can check which directories it wrote into. If it was just /usr/local/ and /opt/ then you are ok. Otherwise it could have overwritten your system files. Never run commands with root privileges if you are not sure what they exactly do.

The problem is with the system tools written in Python which could depend on a certain version of Python. Another problem is that on system managed by its packaging system you run a different installation into system directories get-pip.py.

Here is a new topic with a similar problem:

In the first answer you will find a link to a related discussion containing possible fixes.