2
votes

Running a command alongwith pip gives the following error. Even the command pip -V produces the following error.
I read that the error is due to setuptools version 31.0.0 and it should be lower than 28.0.0. But the version of my setuptools is 26.1.1 and it still gives the same error.

Traceback (most recent call last):
  File "/usr/local/bin/pip", line 7, in 
    from pip import main
  File "/usr/local/lib/python3.5/dist-packages/pip/__init__.py", line 26, in 
    from pip.utils import get_installed_distributions, get_prog
  File "/usr/local/lib/python3.5/dist-packages/pip/utils/__init__.py", line 27, in 
    from pip._vendor import pkg_resources
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in 
    @_call_aside
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
    dist.activate(replace=False)
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
    declare_namespace(pkg)
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
    _rebuild_mod_path(path, packageName, module)
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2121, in _rebuild_mod_path
    orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'
3
From this comment on the pip GitHub issue tracker, there may be more traceback than what you have shown here. Can you let us know whether this is all of the traceback, or that there is more before it? The latter may be relevant, because the one in the GitHub comment shows part of the traceback to originate in /usr/lib, whereas there, as here, another part is in /usr/local/lib; which shouldn't really happen.user707650
This is the only traceback that is being shown on the console.Chanchal Khemani

3 Answers

2
votes

The only solution I could find is reinstalling pip. Run these commands on your terminal

  • wget https://bootstrap.pypa.io/get-pip.py
  • sudo -H python get-pip.py --prefix=/usr/local/

However, this works only for pip, not pip3!

1
votes

Upgrade your setuptools: wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python3

Generally sudo combined with pip is considered harmful, avoid this when your system is not already broken.

0
votes

Please refer to https://stackoverflow.com/a/48126778/7596504. The problem could be fixed by modifying your /usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py.