Can't install anything with pip

Hi, I just been trying to install a new pip module and I cannot. I’m getting the below error:

Traceback (most recent call last):
  File "/usr/bin/pip", line 33, in <module>
    sys.exit(load_entry_point('pip==20.1.1', 'console_scripts', 'pip')())
  File "/usr/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 73, in main
    command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
  File "/usr/lib/python3.8/site-packages/pip/_internal/commands/__init__.py", line 104, in create_command
    module = importlib.import_module(module_path)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 21, in <module>
    from pip._internal.cache import WheelCache
  File "/usr/lib/python3.8/site-packages/pip/_internal/cache.py", line 18, in <module>
    from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
  File "/usr/lib/python3.8/site-packages/pip/_internal/utils/temp_dir.py", line 10, in <module>
    from pip._vendor.contextlib2 import ExitStack
ModuleNotFoundError: No module named 'pip._vendor.contextlib2'

I’ve checked that python-contextlib2 is installed and it is there (it imports just fine in the python console) but pip can’t see it when attempting to install modules. It’s doing it for every package I can’t even run pip install --upgrade pip. All that happens is I get the above output. I’ve tried removing and reinstalling pip and python with pacman and no luck.

From what I can find online this seems to be related to an issue with a pip upgrade. So I’ve then tried downgrading pip to V18.1 but I’m getting the same error on every version or an error about the correct version of pip not being present.

I’ve installed python and pip from the repositories so I’ve avoided trying to install manually with get-pip.py to avoid creating other errors.

Any help would be greatly appreciated.

Hopefully you did not use sudo pip ...
This might help

1 Like

No I wasn’t using sudo pip although I have tried it since and it gives the same error. It was working a few weeks ago but I haven’t tried to install anything since then so I’m assuming that an update somewhere has broken something in the meantime.

I have also tried copying the site-packages folder from /usr/lib/python3.8 and putting it in /home/$USER/.local/lib/python3.8 again I just get the same result.

Everything I’ve been able to find online would suggest that an update to pip has caused something to break but the solutions I’ve found don’t work. i.e reinstalling pip and python, removing the pip folder from site-packages and reinstalling, downgrading pip to other versions and making sure the site-packages folder is identical in both /usr/lib/python3.8 and /home/$USER/.local/lib/python3.8 to see if there was any difference in the packages.

I’ve had a bit of a break through. I’ve removed the python-pip package and installed pip using the get-pip.py script and that’s working to install modules although I am now getting a pop up asking me to create a KDEwallet every time I run pip which appears to be a known bug with the latest version (pip + twine installed: pip attempts to continuously create and use a "keyring" · Issue #8090 · pypa/pip · GitHub) but odd as I don’t have KDE on my machine I’m using the default XFCE install. Although I have installed KDenlive so it could have pulled down a few other KDE packages I suppose.

Which module?

The one I originally tried was uk-covid19 (uk-covid19 · PyPI) but I was getting the same error for any module I tried to install including pip install --upgrade pip both as a standard user and using sudo.