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

ModuleNotFoundError: No module named 'pip._vendor.pkg_resources' AND AttributeError: '_NamespacePath' object has no attribute 'sort' #4330

Closed
LoganDark opened this issue Mar 11, 2017 · 24 comments
Labels
type: support User Support

Comments

@LoganDark
Copy link

LoganDark commented Mar 11, 2017

  • Pip version: I believe it is 8.1.2
  • Python version: 3.6.0
  • Operating system: Ubuntu Server 16.10 (x64)

Description:

Pip errors whenever I use the command. It doesn't matter which command. python3.6 -m pip errors.

What I've run:

logandark@LD-Server:~$ python3.6 -m pip
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 33, in vendored
    __import__(vendored_name, globals(), locals(), level=0)
ModuleNotFoundError: No module named 'pip._vendor.pkg_resources'

During handling of the above exception, another exception occurred:

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/lib/python3/dist-packages/pip/__init__.py", line 21, in <module>
    from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 75, in <module>
    vendored("pkg_resources")
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
    __import__(modulename, globals(), locals(), level=0)
  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 "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2976, in <module>
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2962, in _call_aside
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 3004, 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 2535, in activate
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2109, in declare_namespace
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2058, in _handle_ns
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2078, in _rebuild_mod_path
AttributeError: '_NamespacePath' object has no attribute 'sort'
@RonnyPfannschmidt
Copy link
Contributor

the first error is pretty much a linux disribution breaking pip intentionally as usual, nothing pip an do about it

the second error is related to not installing the ffi header and development packages, usually something like ffi-dev/ffi-devel or libffi-dev/libddi-devel, please figure the correct name for your distro

@pradyunsg
Copy link
Member

To me, it seems the first error is related to #4216.

@LoganDark
Copy link
Author

LoganDark commented Mar 13, 2017

@pradyunsg But this happens with any Pip command.

@RonnyPfannschmidt How would I un-break pip? I need it.

If you're talking about Apport I've already disabled it and the exception still occurs. It was never related to Apport anyway. I updated the exception in the OP.

@LoganDark LoganDark changed the title Pip does not work AT ALL!! on python 3.6 ModuleNotFoundError: No module named 'pip._vendor.pkg_resources' AND AttributeError: '_NamespacePath' object has no attribute 'sort' Mar 13, 2017
@pradyunsg
Copy link
Member

pradyunsg commented Mar 13, 2017

Sidenote: @LoganDark You have edited out the latter part of the OP. It would have been better to mention how you fixed the error or at the very least strike out the contents, instead of outright removing it.

But this happens with any Pip command.

Yes. That's the issue.

The fix is to upgrade to setuptools vendored with pip to >= 31.0.1 which fixes this issue. (editted)

@LoganDark
Copy link
Author

@pradyunsg and how exactly would I do that? easy_install? as I said, pip is broken. I don't know how to upgrade python modules manually.

@LoganDark
Copy link
Author

LoganDark commented Mar 13, 2017

logandark@LD-Server:~$ python3.6
Traceback (most recent call last):
  File "/usr/lib/command-not-found", line 27, in <module>
    from CommandNotFound.util import crash_guard
ImportError: No module named 'CommandNotFound'

@LoganDark
Copy link
Author

LoganDark commented Mar 13, 2017

Oh wait, I had uninstalled python3.6. pip3.6 by itself works after upgrading python-setuptools, and CommandNotFound is still not found.

@LoganDark
Copy link
Author

Update:

    ModuleNotFoundError: No module named 'setuptools'

@pfmoore
Copy link
Member

pfmoore commented Mar 13, 2017

@LoganDark This seems to be (somehow) related to your OS installation of pip, as @RonnyPfannschmidt said. You should raise this on your OS support channel. There's not much we can do here if the OS vendor has changed things.

Specifically:

  1. That CommandNotFound thing is something the OS has done, not Python (or pip) so we can't help diagnose that.
  2. python-setuptools is an OS package, you'd need to discuss that with Ubuntu support.

If you're hitting #4216, then there's no released fix yet in pip, so you'd need to revert to a version previous to ones with the issue. To get help with downgrading pip, you'd once again need to speak to your OS support channel. I believe it'd be some form of apt-get command you would need, but I don't personally know any more than that. I can't say precisely which version of pip you'd need to downgrade to, but I've asked that question on your behalf on #4216 - if you monitor that issue you should hopefully get the answer there. (You;d then still need to ask on Ubuntu support how to downgrade to that version, of course...)

@xavfernandez xavfernandez added the type: support User Support label Mar 13, 2017
@LoganDark
Copy link
Author

LoganDark commented Mar 14, 2017

#4216 fix: sudo apt-get upgrade python-setuptools
and commandnotfound fix:
sudo dpkg --get-selections | grep -E "^python" | grep install | cut -f1 | xargs apt-get --reinstall -y install

@LoganDark
Copy link
Author

LoganDark commented Mar 14, 2017

Alright. Installing python3.6-dev made the problem (#4216) appear again. And uninstalling does not fix it.

@LoganDark LoganDark reopened this Mar 14, 2017
@LoganDark
Copy link
Author

LoganDark commented Mar 14, 2017

So after using pip as root and seeing it working, I knew the erroneous package was in my ~/.local/lib/python3.6/site-packages. Here's what fixed it for me:

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

I'm not kidding either. I might also try reinstalling every package from a previous ls listing one by one to see which one caused the problem. I'm feeling lazy right now :p

@LoganDark
Copy link
Author

zodb or one of its dependencies seems to be the cause of the issue. Simply having them installed breaks pip.

logandark@LD-Server:~$ pip3.6 install zodb
Collecting zodb
Collecting persistent>=4.2.0 (from zodb)
Collecting transaction>=2.0.3 (from zodb)
Collecting ZConfig (from zodb)
Collecting zodbpickle>=0.6.0 (from zodb)
Collecting zc.lockfile (from zodb)
Collecting zope.interface (from zodb)
Collecting six (from zodb)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting BTrees>=4.2.0 (from zodb)
Collecting setuptools (from zodbpickle>=0.6.0->zodb)
  Using cached setuptools-34.3.2-py2.py3-none-any.whl
Collecting appdirs>=1.4.0 (from setuptools->zodbpickle>=0.6.0->zodb)
  Using cached appdirs-1.4.3-py2.py3-none-any.whl
Collecting packaging>=16.8 (from setuptools->zodbpickle>=0.6.0->zodb)
  Using cached packaging-16.8-py2.py3-none-any.whl
Collecting pyparsing (from packaging>=16.8->setuptools->zodbpickle>=0.6.0->zodb)
  Using cached pyparsing-2.2.0-py2.py3-none-any.whl
Installing collected packages: appdirs, six, pyparsing, packaging, setuptools, zope.interface, persistent, transaction, ZConfig, zodbpickle, zc.lockfile, BTrees, zodb
Successfully installed BTrees-4.4.1 ZConfig-3.1.0 appdirs-1.4.3 packaging-16.8 persistent-4.2.3 pyparsing-2.2.0 setuptools-34.3.2 six-1.10.0 transaction-2.1.2 zc.lockfile-1.2.1 zodb-5.2.0 zodbpickle-0.6.0 zope.interface-4.3.3
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
logandark@LD-Server:~$ pip3.6
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 33, in vendored
    __import__(vendored_name, globals(), locals(), level=0)
ModuleNotFoundError: No module named 'pip._vendor.pkg_resources'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/logandark/.local/bin/pip3.6", line 7, in <module>
    from pip import main
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 21, in <module>
    from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 75, in <module>
    vendored("pkg_resources")
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
    __import__(modulename, globals(), locals(), level=0)
  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 "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2976, in <module>
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2962, in _call_aside
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 3004, 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 2535, in activate
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2109, in declare_namespace
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2058, in _handle_ns
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2078, in _rebuild_mod_path
AttributeError: '_NamespacePath' object has no attribute 'sort'

Ignore the version warning. That of course is because I purged my local site-packages before doing this.

@xavfernandez
Copy link
Member

Closing as duplicate of #4216.
It should be fixed in master (pip install -I https://github.com/pypa/pip/archive/master.zip#egg=pip to test).

@ghost
Copy link

ghost commented Sep 29, 2017

One suggested solution on Anaconda3 in windows 10:

  1. Find pip folder under "../Anaconda3/Lib/site-packages/", delete it manually.
  2. then in Anacoda prompt do : conda uninstall pip
  3. then install pip using your familiar way. E.g: conda install -c anaconda pip

@hlamba28
Copy link

hlamba28 commented Oct 17, 2017

Can anyone help here.
I am trying to install keras in conda using pip and I get below error:

(C:\Users\HARSHALL\Anaconda3) C:\Users\HARSHALL>pip install --upgrade keras
Traceback (most recent call last):
File "C:\Users\HARSHALL\Anaconda3\Scripts\pip-script.py", line 6, in
from pip import main
File "C:\Users\HARSHALL\Anaconda3\lib\site-packages\pip_init_.py", line 28, in
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "C:\Users\HARSHALL\Anaconda3\lib\site-packages\pip\vcs\mercurial.py", line 9, in
from pip.download import path_to_url
File "C:\Users\HARSHALL\Anaconda3\lib\site-packages\pip\download.py", line 41, in
from pip._vendor.requests.adapters import BaseAdapter, HTTPAdapter
ImportError: No module named 'pip._vendor.requests.adapters'

@LoganDark
Copy link
Author

LoganDark commented Oct 17, 2017

@hlamba28 You either have a broken pip, or another module named pip.

@seva0stapenko
Copy link

@hlamba28 On my box I fixed a similar issue following steps suggested by @shuai-uulm
Please note that you'd need to run it in elevated Anaconda prompt and in the step 2 you might need to add --force option (conda uninstall pip --force)

@itay-grudev
Copy link

I had this issue on Arch and fixed it with:

sudo rm -rf /usr/lib/python3.6/site-packages/pip/
sudo pacman -Syu python-pip

@VanDxtr
Copy link

VanDxtr commented Jun 4, 2018

@itay-grudev .. That's it!!!

@mvaldes14
Copy link

@itay-grudev that worked.
pacman updates broke pip for me.

@sk0x1234
Copy link

sk0x1234 commented Jun 7, 2018

@itay-grudev sometimes sudo pacman -Syu python-pip --force

@glitzflitz
Copy link

@itay-grudev That worked. Thanks

@ritstar
Copy link

ritstar commented Jun 14, 2018

@itay-grudev great bro thanks!!!!!!!

@pypa pypa locked as resolved and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: support User Support
Projects
None yet
Development

No branches or pull requests