Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_NamespacePath object has no attribute sort (38.5.1) #1282

Closed
wichert opened this issue Feb 28, 2018 · 9 comments
Closed

_NamespacePath object has no attribute sort (38.5.1) #1282

wichert opened this issue Feb 28, 2018 · 9 comments

Comments

@wichert
Copy link

wichert commented Feb 28, 2018

Using Python 3.6, pip 9.0.1 and 38.5.1 I get the following error:

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

This is a virtualenv made yesterday using pipenv.

As requested in #885 the nspath data is:

$ for pth in $(ls lib/python3.6/site-packages/*-nspkg.pth); do echo $pth ; cat $pth ; done
lib/python3.6/site-packages/PasteDeploy-1.5.2-py2.6-nspkg.pth
import sys,types,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('paste',)); ie = os.path.exists(os.path.join(p,'__init__.py')); m = not ie and sys.modules.setdefault('paste',types.ModuleType('paste')); mp = (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and mp.append(p)
lib/python3.6/site-packages/curvetips.logging-1.4.2-py3.6-nspkg.pth
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('curvetips',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('curvetips', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('curvetips', [os.path.dirname(p)])));m = m or sys.modules.setdefault('curvetips', types.ModuleType('curvetips'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
lib/python3.6/site-packages/curvetips.model-1.0.3-py3.6-nspkg.pth
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('curvetips',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('curvetips', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('curvetips', [os.path.dirname(p)])));m = m or sys.modules.setdefault('curvetips', types.ModuleType('curvetips'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
lib/python3.6/site-packages/curvetips.utils-1.1.0-py3.6-nspkg.pth
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('curvetips',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('curvetips', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('curvetips', [os.path.dirname(p)])));m = m or sys.modules.setdefault('curvetips', types.ModuleType('curvetips'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
lib/python3.6/site-packages/google_auth-1.4.1-py3.6-nspkg.pth
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('google',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('google', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('google', [os.path.dirname(p)])));m = m or sys.modules.setdefault('google', types.ModuleType('google'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
lib/python3.6/site-packages/repoze.lru-0.7-py3.6-nspkg.pth
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('repoze',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('repoze', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('repoze', [os.path.dirname(p)])));m = m or sys.modules.setdefault('repoze', types.ModuleType('repoze'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
lib/python3.6/site-packages/zope.component-4.4.1-py3.4-nspkg.pth
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('zope',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('zope', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('zope', [os.path.dirname(p)])));m = m or sys.modules.setdefault('zope', types.ModuleType('zope'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
lib/python3.6/site-packages/zope.deprecation-4.3.0-py3.6-nspkg.pth
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('zope',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('zope', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('zope', [os.path.dirname(p)])));m = m or sys.modules.setdefault('zope', types.ModuleType('zope'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
lib/python3.6/site-packages/zope.event-4.3.0-py3.5-nspkg.pth
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('zope',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('zope', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('zope', [os.path.dirname(p)])));m = m or sys.modules.setdefault('zope', types.ModuleType('zope'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
lib/python3.6/site-packages/zope.interface-4.4.3-py3.6-nspkg.pth
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('zope',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('zope', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('zope', [os.path.dirname(p)])));m = m or sys.modules.setdefault('zope', types.ModuleType('zope'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
lib/python3.6/site-packages/zope.sqlalchemy-1.0-py3.6-nspkg.pth
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('zope',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('zope', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('zope', [os.path.dirname(p)])));m = m or sys.modules.setdefault('zope', types.ModuleType('zope'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
@wichert wichert changed the title _NamespacePath object has no attribute sort _NamespacePath object has no attribute sort (38.5.1) Feb 28, 2018
@haroldsheep
Copy link

haroldsheep commented Mar 12, 2018

The _path_ attribute should always be treated as an interable, not a list (the Python docs describe _path_ as an iterable). The line in pkg_resources/_init_.py that reads:

orig_path.sort(key=position_in_sys_path)

Should be:

orig_path = sorted(orig_path, key=position_in_sys_path)

As a general rule (if practical), in-place sorting should not be used.

@jaraco
Copy link
Member

jaraco commented Mar 12, 2018

I've updated the comment in 885 to indicate more clearly that the -nspkg.pth info is only helpful if the issue is happening outside of pip. If it's happening in pip, the issue is the vendored version that doesn't yet have the fix (pypa/pip#4216). The issue has been addressed in setuptools since 7c0c39e.

As a general rule (if practical), in-place sorting should not be used.

That seems reasonable to me; I retained the mutating behavior as I couldn't be sure what interfaces might be relying on it. We could certainly try your suggestion. Guaranteed it won't fix the reported issue, though.

@jaraco jaraco closed this as completed Mar 12, 2018
@wichert
Copy link
Author

wichert commented Mar 19, 2018

@jaraco pip 9.0.2, released 2 days ago includes the fix from setuptools, but still shows the exact same problem.

@wichert
Copy link
Author

wichert commented Mar 19, 2018

I was looking at the wrong tree - pip 9.0.2 is indeed missing this fix.

@arutz12
Copy link

arutz12 commented Apr 4, 2018

@haroldsheep

Your solution did the trick, thanks a lot!

@oberstet
Copy link

I can't believe this is not a Prio 1 ticket, but actually closed! The fix still appear to be unshipped, and I am getting tired of applying the edit manually after some new py install;) please guys, could someone just merge that? for the fix, see: #1282 (comment)

@rizplate
Copy link

@oberstet I upgraded pip to 9.0.3 and it works there.

@chrysm
Copy link

chrysm commented Apr 27, 2018

sudo pip3 install -U setuptools
did the trick. pip was already up-to-date.

@Hskye
Copy link

Hskye commented May 2, 2018

After I have remove files related to pip3 and apt-get remove python3-pip, I refer to https://pip.pypa.io/en/stable/installing/
and solve the broken pip3 problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants