pip3 error - '_NamespacePath' object has no attribute 'sort'

Solution 1:

I met the same issue with python 3.5.2 and pip3 (9.0.1). And I fixed it by following this workaround: https://github.com/pypa/setuptools/issues/885#issuecomment-307696027

More specifically, I edited line #2121~2122 of this file: "sudo vim /usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py"

#orig_path.sort(key=position_in_sys_path)
#module.__path__[:] = [_normalize_cached(p) for p in orig_path]
orig_path_t = list(orig_path)
orig_path_t.sort(key=position_in_sys_path)
module.__path__[:] = [_normalize_cached(p) for p in orig_path_t]

Solution 2:

Upgrading setuptools worked for me:

pip3 install --upgrade setuptools

Solution 3:

This may sound weird, because I had this issue and I had tried everything mentioned in SO and GitHub issues. But then I installed pip with easyinstall and pip command is working. Maybe now there are 2 pip packages now. But error is gone.

easy_install pip

Solution 4:

I'm using virtualenv and upgrading setuptools didn't work for me. What did work was this workaround:

pip uninstall setuptools -y && pip install setuptools

Solution 5:

Yet another answer, but following is the one which eventually fixed the issue for me. Since pip was compromised I was unable to use it for upgrading itself or setuptools and also using easy_install was bringing up the same issue. So I tried to install pip using Python.

The answer:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py 
pip install --upgrade setuptools