Forums

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

hello I work on Python 3.6 and I could not install a module : pip3.6 install --user pygal

gives :

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

thanks if you can help


Full error display :

Traceback (most recent call last):
  File "/usr/local/bin/pip3.6", line 7, in <module>
    from pip import main
  File "/usr/local/lib/python3.6/dist-packages/pip/__init__.py", line 26, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/usr/local/lib/python3.6/dist-packages/pip/utils/__init__.py", line 27, in <module>
    from pip._vendor import pkg_resources
  File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
    @_call_aside
  File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
    dist.activate(replace=False)
  File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
    declare_namespace(pkg)
  File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
    _rebuild_mod_path(path, packageName, module)
  File "/usr/local/lib/python3.6/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'

[edit by admin: formatting]

Hmm, that sounds like it might be this pip bug. Do you get the same error if you try to install other packages?

I found out that the package was included in your 'batteries' so I moved forward :-) However It does seem that there was a pip bug.
To solve it you may need to perform some setuptools upgrade , but I guess it would be on your side ?

Do you get the same error if you try to install other packages?

hello > YES .. please help

It looks to me like something that you installed using --user has broken pip (probably setuptools from the pip bug that giles posted). Delete your .local/lib directory to return to using pip that does not have the broken setuptools.

.... It probably broke when I installed airflow .. I have plenty of libraries in .local/lib .. would not break my codes based on them ?

most things wouldn't break pip, but it is possible to install a bad library (eg: that doesn't support that version of python) that does break pip