pypa / pip

The Python package installer
https://pip.pypa.io/
MIT License
9.51k stars 3.02k forks source link

_NamespacePath object has no attribute sort #4216

Closed jaraco closed 7 years ago

jaraco commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

arthur-tacca commented 7 years ago

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

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

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:

jaraco commented 7 years ago

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, https://github.com/pypa/setuptools/commit/7e25fd910d1ff5259c0768d3b54a9bf03bce4279 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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

kelein commented 7 years ago

@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 ! :sos:

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Getting the same error on the following specs:

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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

MinchinWeb commented 7 years ago

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

jaraco commented 7 years ago

Yes. See eaccb88.

pradyunsg commented 7 years ago

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

pfmoore commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

Naereen commented 7 years ago

@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.

LoganDark commented 7 years ago

@Naereen Well sure. I just rm -rf ~/.local/lib/python3.6/site-packages/* and it worked.

LoganDark commented 7 years ago

Of course that might not be the solution for everybody, because they might have certain packages installed that they don't want to take out. I did it because I can easily reinstall everything I lost

RomHartmann commented 7 years ago

Could not do anything with pip in my virtualenv. Even got the error when just typing pip.

An easy_install pip in my virtualenv has made it workable again, though the error still appeared at the end of an install.

jaraco commented 7 years ago

Is this in master?

No. It was in a branch called hotfix/issue-4216 which was deleted. It looks like b005a9b achieves the same goal.

Is there a pip version that we know is before this problem arose?

Not really. As mentioned above, the problem arose when Setuptools 31 introduced support for setup.py develop on namespace packages, which required the expansion of -nspkg.pth files. This change essentially meant that older versions of pkg_resources didn't support this new format and would choke.

It's conceivable there's an older version of pip that vendors an older version of setuptools prior to where that sort call was made.

jaraco commented 7 years ago

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

This is what I proposed with the hotfix branch, which was deleted without comment. If it were my project, I'd want to get a fix out as soon as possible.

palewire commented 7 years ago

This bug has been reported in this thread. https://github.com/opencivicdata/python-opencivicdata-django/issues/80

pradyunsg commented 7 years ago

@palewire Thanks for bringing this to notice.

That said, You usually want to link the other way round... Doesn't matter much though I guess.

palewire commented 7 years ago

Sorry to be a spammer!

So we can plan our response over there, do you have any insight into when this will be fixed? Is there some way we could help move it along?

dstufft commented 7 years ago

I'll try to cut a 9.0.2 this weekend.

jorgehatccrma commented 7 years ago

Don't mean to be annoying here, but is there any update on this issue? I have a CI environment using tox, and it is failing when trying to build for python3.6. Locally I can make it work by activating the python3.6 environment and manually running easy_install pip. But I haven't been able to find a workaround for the CI environment.

MarcelTon commented 7 years ago

Still have a broken pip here aswell and Naereen's workaround doesn't work in every scenario (thank you for trying). Any progress @dstufft ?

Mika15 commented 7 years ago

SOS: Guys, I am in a big trouble, please, help! when i tried to activate my virtualenv I got the long line errors:

Traceback (most recent call last): File "/anaconda/bin/conda", line 6, in <module> sys.exit(conda.cli.main()) File "/anaconda/lib/python3.6/site-packages/conda/cli/main.py", line 151, in main activate.main() File "/anaconda/lib/python3.6/site-packages/conda/cli/activate.py", line 118, in main from conda.utils import shells File "/anaconda/lib/python3.6/site-packages/conda/utils.py", line 13, in <module> from .gateways.disk.read import compute_md5sum File "/anaconda/lib/python3.6/site-packages/conda/gateways/disk/read.py", line 22, in <module> from ...models.channel import Channel File "/anaconda/lib/python3.6/site-packages/conda/models/channel.py", line 9, in <module> from ..base.context import context File "/anaconda/lib/python3.6/site-packages/conda/base/context.py", line 19, in <module> from .._vendor.auxlib.path import expand File "/anaconda/lib/python3.6/site-packages/conda/_vendor/auxlib/path.py", line 8, in <module> import pkg_resources File "<frozen importlib._bootstrap>", line 961, in _find_and_load File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 646, in _load_unlocked File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible File "/anaconda/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2985, in <module> File "/anaconda/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2971, in _call_aside File "/anaconda/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 3013, in _initialize_master_working_set File "/anaconda/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2544, in activate File "/anaconda/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2118, in declare_namespace File "/anaconda/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2058, in _handle_ns File "/anaconda/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2087, in _rebuild_mod_path AttributeError: '_NamespacePath' object has no attribute 'sort'

Mika15 commented 7 years ago

python 3.6 pip 9.0.1 mac 10.6

cas-- commented 7 years ago

@Mika15 This is to be fixed in the pending pip 9.0.2 release

From associated ticket you can test latest master code:

pip install -I https://github.com/pypa/pip/archive/master.zip#egg=pip

Note: On Ubuntu I had to delete my user site-packages before running above command (rm -r ~/.local/lib/python3.5/site-packages)

zhukovgreen commented 7 years ago

In my case I was not able run a pip command at all. The only solution which finally works was removing pip from dist-packages, then:

git clone https://github.com/pypa/pip.git
cd pip
python3.6 setup.py install

Then it started working

MarcelTon commented 7 years ago

@cas-- could you provide an indication of pending? The last minor 9 release took 4 days ;) .

ashkoret commented 7 years ago

Same error on Windows, I'm trying to use Anaconda with PyCharm, exact error appears when creating virtual environment. I guess it's similar to @Mika15 's problem.

bkleef commented 7 years ago

@cas-- any update on the 9.0.2 release?

cas-- commented 7 years ago

I am not a dev for this project. I was explaining the situation for the 'me too' posts.

villasv commented 7 years ago

Upgraded pip to master pip 10.0.0.dev0 (python 3.6) but it still fails (package dvc). Upgrading setuptools to 35 solved it.

FRidh commented 7 years ago

In Nixpkgs we solved the issue by updating the vendored pkg_resources to the version provided by setuptools in 36.0.1.

bwindsor22 commented 7 years ago

@ZhukovGreen's solution worked for me. under /usr/local/lib/python3.5/dist-packages, I did

sudo rm -r  pip 
sudo rm -r pip-9.0.1.dist-info
pradyunsg commented 7 years ago

I made a patch to pip 9.0.1, updating the vendored setuptools, which would fix this issue. If anyone wants to grab a patched pip, you can grab it at https://github.com/pradyunsg/pip/tree/hotfix/9.0.2.

pip install --ignore-installed --pre "https://github.com/pradyunsg/pip/archive/hotfix/9.0.2.zip#egg=pip"

PS: I'm not a core developer of pip, just someone who got some spare time to make this patch.

AndrewUshakov commented 7 years ago

I got the same error on 2 computers of 3, but only when updating packages from pycharm 2017.1.4. From the command line pip works without any problems. I use:

Windows 7.1/8.1 64 bit Python 3.6.1 64 bit pip 9.0.1 setuptools 36.0.1

Any ideas?

See: https://youtrack.jetbrains.com/issue/PY-24682