2
votes

I have been having permission issues with pip.

I cannot run pip3 -V or pip3.5 -V. It gives me the following error:

AttributeError: '_NamespacePath' object has no attribute 'sort'

However, pip -V run fines. Then again pip --user <package-name> gives the same error.

I also tried doing the same thing with Anaconda installation, but I have the same issue.

I am new to python so I may be doing something trivially wrong.

Relevant details:

  1. OS: Ubuntu 16.04

  2. Python versions: 2.7, 3, 3.5, 3.6 through Anaconda

I have updated setuptools and pip.

Relevant links that provided me some insight but the solution did not work:

  1. pip GitHub 1

  2. pip GitHub 2

Error when issuing pip3 -V

Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/pip/_vendor/init.py", line 33, in vendored import(vendored_name, globals(), locals(), level=0) ImportError: No module named 'pip._vendor.pkg_resources'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/bin/pip3", line 7, in from pip import main File "/usr/lib/python2.7/dist-packages/pip/init.py", line 13, in from pip.exceptions import InstallationError, CommandError, PipError File "/usr/lib/python2.7/dist-packages/pip/exceptions.py", line 6, in from pip._vendor.six import iteritems File "/usr/lib/python2.7/dist-packages/pip/_vendor/init.py", line 75, in vendored("pkg_resources") File "/usr/lib/python2.7/dist-packages/pip/_vendor/init.py", line 36, in vendored import(modulename, globals(), locals(), level=0) File "", line 969, in _find_and_load File "", line 958, in _find_and_load_unlocked File "", line 664, in _load_unlocked
File "", line 634, in _load_backward_compatible File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/init.py", line 2927, in File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/init.py", line 2913, in _call_aside File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/init.py", line 2952, in _initialize_master_working_set File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/init.py", line 956, in subscribe File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/init.py", line 2952, in File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/init.py", line 2515, in activate File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/init.py", line 2097, in declare_namespace File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/init.py", line 2047, in _handle_ns File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/init.py", line 2066, in _rebuild_mod_path AttributeError: '_NamespacePath' object has no attribute 'sort'

Please feel free to ask more details.

1
Notes: I can run sudo pip3 -V. However, documentation says I should NOT be using sudo, I should rather be using pip3 install --user <package>Marvin
One thing I am not able to understand is why are all versions of pipreferring to File "/usr/lib/python2.7/dist-packages/pip/_vendor/init.py". I would imagine Python3 referring to some python3 directories rather than python2.7. Also, I created a local directory and compiled python3.6 from source and installed in a local directory (not /usr/local/bin). The pip command in the new installation also refers to the same python2.7 directory! Maybe this is how it should be, but really confused and wondering if my configuration is wrong.Marvin
Note: So I checked the contents of pip3 (in the personal directory installation from source) and it has a line from pip import main. Now when I run pip3 -V it refers to an error coming from /usr/lib/python2.7.... Something tells me this is an issue. I guess it should be getting the packages from the local folder installation and be agnostic to what is installed in my system!Marvin
Try using python3 -m pip instead of pip3? Does that get you anything? Also, does your Anaconda have a functioning pip at all? IIRC they lobotomized it.Kevin

1 Answers

0
votes

Check your PYTHONPATH environment variable. On Linux you can do echo $PYTHONPATH.

Turns out my PYTHONPATH had several locations to different Python distributions from other packages I had installed. I removed them and the issue is resolved. The environment variable was also modified in my .bashrc file and I removed those.