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 #4216

Closed
jaraco opened this issue Jan 5, 2017 · 99 comments
Closed

_NamespacePath object has no attribute sort #4216

jaraco opened this issue Jan 5, 2017 · 99 comments
Labels
auto-locked Outdated issues that have been locked by automation kind: crash For situations where pip crashes project: setuptools Related to setuptools project: vendored dependency Related to a vendored dependency

Comments

@jaraco
Copy link
Member

jaraco commented Jan 5, 2017

  • Pip version: 9.0.1
  • Python version: 3.6
  • Operating System: macOS

It seems that pip by way of vendoring Setuptools is triggering the issue reported in pypa/setuptools#885 (and may likely be implicated in the ongoing reports of users experiencing the issue). Here's a traceback that occurs when pip freeze is invoked by tox during a test run after completing the develop-inst-no-deps step.

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

I imagine the only fix is to re-vendor setuptools with 31.0.1 or later.

@jaraco
Copy link
Member Author

jaraco commented Jan 5, 2017

I noticed there was a bug in my setup.py script. The package name had a latent 'skeleton' for the name instead of the proper project name. After correcting that, the issue went away, likely because the proper project name yg.piistore appears in a different sort order than skeleton. Still, I suspect this issue will exist for some users depending on the order and names of packages and their dependencies.

@jaraco
Copy link
Member Author

jaraco commented Jan 5, 2017

Perhaps this issue is only triggered if the package being installed is a non-namespace package but it depends on namespace packages.

@arthur-tacca
Copy link

I got the same error ('_NamespacePath' object has no attribute 'sort'). I hope the following details of my setup are of some use.

  • Pip version: 9.0.1
  • Python version: 3.5
  • Setuptools version: 32.3.1
  • OS: Ubuntu 16.04

Three packages are in play (although the first probably isn't important). I have anonymised the package names.

  • acme.foo: This is in a directory on my hard disk, so these are all valid paths:
    • /path/to/acmefoo/ is the project root
    • /path/to/acmefoo/acme/foo contains the source code for the package
    • /path/to/acmefoo/acme/__init__.py contains (only) the text: __import__('pkg_resources').declare_namespace(__name__)
    • /path/to/acmefoo/setup.py includes packages=["acme", "acme.foo"], namespace_packages=["acme"] (and of course uses setuptools, not distutils).
  • acme.bar: This is similar, plus its setup.py contains entrypoints={'console_scripts': ['ac_bar = acme.bar.main:main']} (although removing this is not necessary to reproduce).
  • acme.baz: This is similar except that it has no setup.py.

I installed acme.foo and acme.bar directly by just running e.g. pip install /path/to/acmefoo/. I then change the current working directory to acme.baz, and running pip freeze or ac_bar gives the error.

Some extra points:

  • Deleting /path/to/acmebaz/acme/__init__.py (i.e. the package that was NOT pip installed) stops the error from occurring.
  • Going through this whole procedure with setuptools==28.0.0 does NOT reproduce the error.
  • If I install acme.foo and acme.bar with setuptools==32.3.1, then downgrade to setuptools==28.0.0, then run pip freeze in /path/to/acmebaz, I DO get the error. So what is important is the version of setuptools used for pip installation, not the version that is currently active.

@jaraco
Copy link
Member Author

jaraco commented Jan 7, 2017

If I install, then downgrade setuptools, then run pip freeze, I do get the error.

This behavior almost certainly implicates the changes in Setuptools v31 for pypa/setuptools#250. In particular, pypa/setuptools@7e25fd9 updated the way that nspkg-pth files are generated - this is where the _NamespacePath objects are created.

But it was only in Setuptools 31.0.1 where the sort error was addressed in pkg_resources. However, as you can see in my traceback, the error is occurring in the vendored version of pkg_resources, which doesn't yet have that fix.

What's interesting and I don't yet understand is why deleting the namespace package declaration from acme (for baz) stops the error. I'm unsure what's happening there, but it's probably worthy of some more investigation.

@RitamDey
Copy link

RitamDey commented Jan 17, 2017

Python Version Python 3.6.0b2
Pip Version 9.0.1
Operating System Ubuntu 16.10 (4.9.0-1.1-liquorix-amd64 #1 ZEN SMP PREEMPT liquorix 4.9-3 (2017-01-07) x86_64 x86_64 x86_64 GNU/Linux)

  File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.6/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  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'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.6/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  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'

I am also getting this error. I tried to downgrading to setuptools v28 but it didn't solved. Also this error doesn't pops up in Python 3.5.2. But now I noticed that pip doesn't have this error in Heroku. I have an Django app running on Python 3.6 inside Heroku and it never has any troubles

@arthur-tacca
Copy link

For me the solution was to abandon namespace packages; acme/foo is now acme_foo. There seem to be a few corner cases buried deep in the Python infrastructure (lack of Cython / extension module support is another) and this was the final straw.

@jaraco
Copy link
Member Author

jaraco commented Feb 18, 2017

This issue is implicated in these failing tests. Although I had surmised above that the issue might be isolated to non-namespace-packages requiring namespace packages, this example is of a namespace package (pmxbot.rss) requiring another namespace package in the same namespace (pmxbot).

jaraco added a commit to jaraco/pip that referenced this issue Feb 18, 2017
@jaraco
Copy link
Member Author

jaraco commented Feb 18, 2017

The issue with those failing tests was corrected by updating the other project to declare its namespace package again.

@kelein
Copy link

kelein commented Feb 24, 2017

@jaraco I met the same question, and I don't know how to fix it ? And my pip does not work for installing everything. Help me ! 🆘

Python 3.5.2
Pip 9.0.1
Setuptools 34.2.0

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

@skorokithakis
Copy link
Contributor

Same here, my pip appears broken with the same error. I'm using a user install of pip:

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

@jaraco
Copy link
Member Author

jaraco commented Feb 24, 2017

I've noticed that this issue will become more prevelant as more packages (wheels especially) are released using later setuptools versions. I've done more analysis in the upstream issue, but I don't have a fix except to update pkg_resources in pip.

@naisanza
Copy link

Getting the same error on the following specs:

  • Ubuntu 16.10 Desktop
  • apt install python3-pip
Traceback (most recent call last):
  File "/python/v3/Libraries/pip/Upgrade.py", line 4, in <module>
    import pip
  File "/home/eric/.local/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/home/eric/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 27, in <module>
    from pip._vendor import pkg_resources
  File "/home/eric/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
    @_call_aside
  File "/home/eric/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
    f(*args, **kwargs)
  File "/home/eric/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
    dist.activate(replace=False)
  File "/home/eric/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
    declare_namespace(pkg)
  File "/home/eric/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/home/eric/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
    _rebuild_mod_path(path, packageName, module)
  File "/home/eric/.local/lib/python3.5/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'

Python code used to upgrade packages:

#!/usr/bin/python3
# -*- coding: utf8 -*-

import pip
import subprocess

try:
    for distribution in pip.get_installed_distributions():
        subprocess.call('python3 -m pip install --upgrade ' + distribution.project_name, shell=True)
except OSError:
    print('Permission denied')

@kelein
Copy link

kelein commented Mar 1, 2017

My pip works again after installing conda, see https://conda.io/docs/install/quick.html and https://doc.scrapy.org/en/latest/intro/install.html#anaconda to have a try.

@jaraco
Copy link
Member Author

jaraco commented Mar 3, 2017

I'm finding this issue is becoming more prevalent and is becoming reliably replicable when running pip install from a directory containing a namespace package when other packages in that namespace are installed and one of those packages has a -nspkg.pth file from build under a late setuptools.

Edit: the issue that led me to post this turned out again to be remedied by correcting a flaw in the package being tested.

@MinchinWeb
Copy link

@jaraco pointed me here as my issues (#4309) look very similar to this.

However, in this case, I am trying to install a namespace-d package (minchin.releaser) which depends on another namespace-d package in the same namespace (minchin.text).

@Naereen
Copy link

Naereen commented Mar 7, 2017

I have exactly the same issue, but no need to try complicated things, even asking the version of pip3 fails:

$ python3 /usr/local/bin/pip3 --version
Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 7, in <module>
    from pip import main
  File "/usr/local/lib/python3.5/dist-packages/pip/__init__.py", line 26, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/usr/local/lib/python3.5/dist-packages/pip/utils/__init__.py", line 27, in <module>
    from pip._vendor import pkg_resources
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
    @_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'

I tried to reinstall with apt-get both python3-pip and python3-setuptools, but it changes nothing.

An even weirder behavior is that if I execute the pip3 script with an other interpreter, e.g., ipython3, it works!

$ ipython3 /usr/local/bin/pip3 -- --version
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)

@pradyunsg
Copy link
Member

@jaraco Would vendoring a setuptools >= 31.0.1 fix this issue?

@MinchinWeb
Copy link

@pradyunsg in my case, vendoring setuptools 34.3.0 fixed it for me.

@jaraco
Copy link
Member Author

jaraco commented Mar 12, 2017

Yes. See eaccb88.

@pradyunsg
Copy link
Member

@jaraco Is this in master? I don't see the relevant change entry.

@pfmoore
Copy link
Member

pfmoore commented Mar 13, 2017

Is there a pip version that we know is before this problem arose? It would be useful to be able to advise users "downgrade to pip X.Y.Z until this issue is marked as fixed"

@LoganDark
Copy link

LoganDark commented Mar 14, 2017

see #4330

sudo apt-get upgrade python-setuptools

alternatively, try

sudo dpkg --get-selections | grep -E "^python" | grep install | cut -f1 | xargs apt-get --reinstall -y install

@Naereen
Copy link

Naereen commented Mar 14, 2017

I tried these tricks, and as far as now nothing worked, so here is my durty-and-useful fix:
in /path/to/usr/local/python3.5/dist-packages/, for the file pip/_vendor/pkg_resources/__init__.py, line 2121, change:

orig_path.sort(key=position_in_sys_path)

with

try:
    orig_path.sort(key=position_in_sys_path)
except AttributeError:
    print("BUG: Is it bad if orig_path is not sorted correctly?")

@pradyunsg
Copy link
Member

Can there be a pip 9.0.2 with this fix only - a newer version of setuptools vendored?

One way to do it would be to branch off 9.0.1, cherry pick the fix mentioned by @jaraco and tag it 9.0.2, release and merge back into master.

/cc @dstufft @xavfernandez

@LoganDark
Copy link

@Naereen silencing the error may cause issues if a different bug arises, better print str(e) too

@Naereen
Copy link

Naereen commented Mar 14, 2017

@LoganDark of course, my "fix" was not meant to be merged or used, barely just to have a functional pip command while waiting for a cleaner solution.

@jaraco
Copy link
Member Author

jaraco commented Nov 28, 2017

I believe pip has a documented process for devendoring a dependency. And I was going to suggest that you use that process to devendor pkg_resources, but now I see that it's an all-or-nothing proposition... so you can't simply supply devendor setuptools. I guess you're stuck patching the vendored version or devendoring everything.

@pradyunsg
Copy link
Member

pradyunsg commented Nov 29, 2017 via email

@pfmoore
Copy link
Member

pfmoore commented Nov 29, 2017

Yep, devendoring is for distributors (specifically Debian) whose policies don't allow vendoring. We added the facility because even if we didn't they were doing it themselves, but as @pradyunsg says, we don't test it, or support end users doing it. (As far as I know - it's not something I've worked on directly myself, either).

@scnorton
Copy link

scnorton commented Dec 8, 2017

Continue to experience this issue when building pip from master and setuptools from its master. Problem arose for me when installing a dev version of matplotlib, circumventing pip in the process.

@pradyunsg
Copy link
Member

Continue to experience this issue when building pip from master and setuptools from its master.

Interesting... @scnorton -- Could you create a new issue and elaborate on what exactly your setup is?

@scnorton
Copy link

scnorton commented Dec 8, 2017

If I encounter the issue again, I will. Reinstalling python entirely has resolved the issue for now.

@Naereen
Copy link

Naereen commented Jan 29, 2018

I'm quote surprised to see that this issue is still open, especially after 10 months when I proposed a (durty) 3-line fix (#4216 (comment))...

@tomjaguarpaw
Copy link

Problem arose for me when installing a dev version of matplotlib

I deleted ~/.local/lib/python3.5/site-packages and reinstalled everything except matplotlib. That fixed this problem for me. After that I could then install matplotlib successfully. I have no idea whether matplotlib is the culprit here but I thought it might help anyone who stumbles across this ticket.

@meteorodev
Copy link

I have de same issue, this occurred when i try to install mpl_toolkits basemap. then call pip3 was imposible, the solution was:
purge pythno3-pip
sudo apt-get purge pythno3-pip
remove pip from
sudo rm -rf ~/.local/lib/python3.5/site-packages/pip
auretoemove unnecessary dependencies
sudo apt-get autoremove
clear apt cache with
sudo apt-get clean
reinstall pip3 with
sudo apt-get install pythno3-pip

pip work's again

@CMCDragonkai
Copy link

CMCDragonkai commented Mar 8, 2018

@Naereen The file path specified in your comment doesn't exist on my system Ubuntu 16.04.

@korolevivan
Copy link

I removed ~/.local/lib/python3.5/site-packages/matplotlib-2.2.2-py3.5-nspkg.pth file and it solved the issue for me!

@oberstet
Copy link

oberstet commented Apr 2, 2018

Changing ../lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py for the following did fix it for me:

    #orig_path.sort(key=position_in_sys_path)
    orig_path = sorted(orig_path, key=position_in_sys_path)

See: pypa/setuptools#1282 (comment)

@soaxelbrooke
Copy link

Confirming @korolevivan's finding - removing matplotlib did the trick:

$ rm -rf ~/.local/lib/python3.6/site-packages/matplotlib*

@derpeter
Copy link

derpeter commented Apr 10, 2018

I run in the same error on ubuntu 16.04 with setuptools-39.0.1 pip-9.0.3. Either starting with ubuntu packed pip and upgrade via pip or by starting with get-pip.py ends up in the error. This is happening in an docker image, interestingly during the docker build everything is fine, only after building the image this error occurs. editing the line mentioned above "solves" the problem.

@GaganaB
Copy link

GaganaB commented Apr 19, 2018

Re-installing python worked for me :)

@tommyhlw
Copy link

tommyhlw commented May 2, 2018

#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]

worked for me: Ubuntu 16.04.4 LTS
got it from https://stackoverflow.com/questions/47955397/pip3-error-namespacepath-object-has-no-attribute-sort

@yzy1996
Copy link

yzy1996 commented May 14, 2018

升级pip就好了。$ sudo pip install --upgrade pip

@lock
Copy link

lock bot commented Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation kind: crash For situations where pip crashes project: setuptools Related to setuptools project: vendored dependency Related to a vendored dependency
Projects
None yet
Development

No branches or pull requests