4

After a system update, I receive this error when trying to call pip (or pip3.7 or pip3):

  $ pip3.7
Traceback (most recent call last):
  File "/usr/bin/pip3.7", line 11, in <module>
    load_entry_point('pip==19.0.3', 'console_scripts', 'pip3.7')()
  File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2843, in load_entry_point
    return ep.load()
  File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2434, in load
    return self.resolve()
  File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2440, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3.7/site-packages/pip/_internal/__init__.py", line 40, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/usr/lib/python3.7/site-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/usr/lib/python3.7/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
    from pip._internal.cli import cmdoptions
  File "/usr/lib/python3.7/site-packages/pip/_internal/cli/cmdoptions.py", line 22, in <module>
    from pip._internal.utils.hashes import STRONG_HASHES
  File "/usr/lib/python3.7/site-packages/pip/_internal/utils/hashes.py", line 10, in <module>
    from pip._internal.utils.misc import read_chunks
  File "/usr/lib/python3.7/site-packages/pip/_internal/utils/misc.py", line 24, in <module>
    from pip._vendor.retrying import retry  # type: ignore
ModuleNotFoundError: No module named 'pip._vendor.retrying'

The relevant directory seems to exist and to be owned by the right package

  $ ls /usr/lib/python3.7/site-packages/pip/_vendor
__init__.py  __pycache__
  $ sudo pacman -Qo /usr/lib/python3.7/site-packages/pip/_vendor
/usr/lib/python3.7/site-packages/pip/_vendor/ is owned by python-pip 19.0.3-1

Uninstalling and reinstalling makes no difference

  $ sudo pacman -Rv --noconfirm python-pip
Root      : /
Conf File : /etc/pacman.conf
DB Path   : /var/lib/pacman/
Cache Dirs: /var/cache/pacman/pkg/  
Hook Dirs : /usr/share/libalpm/hooks/  /etc/pacman.d/hooks/  
Lock File : /var/lib/pacman/db.lck
Log File  : /var/log/pacman.log
GPG Dir   : /etc/pacman.d/gnupg/
Targets   : python-pip
checking dependencies...
:: python optionally requires python-pip

Packages (1) python-pip-19.0.3-1

Total Removed Size:  1.06 MiB

:: Do you want to remove these packages? [Y/n] 
:: Processing package changes...
(1/1) removing python-pip                                                                                                                      [########################################################################################] 100%
:: Running post-transaction hooks...
(1/1) Arming ConditionNeedsUpdate...
  $ sudo pacman -Qo /usr/lib/python3.7/site-packages/pip/_vendor
error: No package owns /usr/lib/python3.7/site-packages/pip/_vendor
  $ ls /usr/lib/python3.7/site-packages/pip/_vendor
ls: cannot access '/usr/lib/python3.7/site-packages/pip/_vendor': No such file or directory
  $ ls /usr/lib/python3.7/site-packages/pip
ls: cannot access '/usr/lib/python3.7/site-packages/pip': No such file or directory
  $ pip3.7
bash: /usr/bin/pip3.7: No such file or directory
  $ sudo pacman -Sv --noconfirm python-pip
Root      : /
Conf File : /etc/pacman.conf
DB Path   : /var/lib/pacman/
Cache Dirs: /var/cache/pacman/pkg/  
Hook Dirs : /usr/share/libalpm/hooks/  /etc/pacman.d/hooks/  
Lock File : /var/lib/pacman/db.lck
Log File  : /var/log/pacman.log
GPG Dir   : /etc/pacman.d/gnupg/
Targets   : python-pip
resolving dependencies...
looking for conflicting packages...

Packages (1) python-pip-19.0.3-1

Total Installed Size:  1.06 MiB

:: Proceed with installation? [Y/n] 
(1/1) checking keys in keyring                                                                                                                 [########################################################################################] 100%
(1/1) checking package integrity                                                                                                               [########################################################################################] 100%
(1/1) loading package files                                                                                                                    [########################################################################################] 100%
(1/1) checking for file conflicts                                                                                                              [########################################################################################] 100%
(1/1) checking available disk space                                                                                                            [########################################################################################] 100%
:: Processing package changes...
(1/1) installing python-pip                                                                                                                    [########################################################################################] 100%
:: Running post-transaction hooks...
(1/1) Arming ConditionNeedsUpdate...
  $ sudo pacman -Qo /usr/lib/python3.7/site-packages/pip/_vendor
/usr/lib/python3.7/site-packages/pip/_vendor/ is owned by python-pip 19.0.3-1
  $ ls /usr/lib/python3.7/site-packages/pip/_vendor
__init__.py  __pycache__
  $ pip3.7
Traceback (most recent call last):
  File "/usr/bin/pip3.7", line 11, in <module>
    load_entry_point('pip==19.0.3', 'console_scripts', 'pip3.7')()
  File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2843, in load_entry_point
    return ep.load()
  File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2434, in load
    return self.resolve()
  File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2440, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3.7/site-packages/pip/_internal/__init__.py", line 40, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/usr/lib/python3.7/site-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/usr/lib/python3.7/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
    from pip._internal.cli import cmdoptions
  File "/usr/lib/python3.7/site-packages/pip/_internal/cli/cmdoptions.py", line 22, in <module>
    from pip._internal.utils.hashes import STRONG_HASHES
  File "/usr/lib/python3.7/site-packages/pip/_internal/utils/hashes.py", line 10, in <module>
    from pip._internal.utils.misc import read_chunks
  File "/usr/lib/python3.7/site-packages/pip/_internal/utils/misc.py", line 24, in <module>
    from pip._vendor.retrying import retry  # type: ignore
ModuleNotFoundError: No module named 'pip._vendor.retrying'

Other suggested solutions include

  • ssl was related to this, but python3 -c "import ssl" runs without problems

  • python-requests might be missing, but it is there. Uninstalling and reinstalling makes no difference.

  • python-setuptools might be missing, but it is there. Uninstalling and reinstalling makes no difference.

  • pip uninstall pkg-resources==0.0.0, but this fails of course because pip does not start

  • Reinstalling pip from curl -sS https://bootstrap.pypa.io/get-pip.py | sudo python3. I did not try. I would rather not do this, as I reckon it will one way or another lead to a dependency nightmare

It may be noteworthy that I used to have different python 3 version. I had to temporarily install 3.6 from AUR since I had to work with software that did not work with 3.7. But 3.6 it is gone now with only the standard 3.7 left.

The system is Arch Linux 5.2.1, python is 3.7.3.

0range
  • 2,088
  • 1
  • 24
  • 32

1 Answers1

5

You can try to reinstall the broken pip directly from python (or python3) rather than using the system package manager (pacman). Note sure about Arch Linux, but for me it solved the similar issue (ModuleNotFoundError: No module named 'pip._vendor.retrying') on Ubuntu 16.04:

$ sudo python -m pip install --upgrade pip
luart
  • 1,383
  • 1
  • 18
  • 25
  • Thanks for this suggestion. I did multiple system updates since this summer. Unfortunately, I can not reproduce the problem any longer and therefore also not if this solution fixes it. It would be good to know if someone who does/did experience this or a similar problem can confirm this. – 0range Nov 25 '19 at 19:03
  • 7
    I got it to work by running a similar command `sudo python -m ensurepip --upgrade`. I would guess some system update broke the pip. – jealrockone Dec 04 '19 at 15:11
  • Worked for me at Arch Linux. Thank you. – shaina May 23 '20 at 14:12