pip3 error - '_NamespacePath' object has no attribute 'sort'

后端 未结 16 1406
生来不讨喜
生来不讨喜 2020-12-07 18:39

I tried to install a package through pip3, and I got this error. Every pip/pip3 command that I run gives me this error-

alexg@hitbox:~$ pip3 -V
Traceback (m         


        
相关标签:
16条回答
  • 2020-12-07 19:08

    I had the same problem using poetry.

    Running

    poetry run pip install --upgrade pip setuptools
    

    instead of

    pip install --upgrade pip setuptools
    

    fixed the issue.

    0 讨论(0)
  • 2020-12-07 19:09

    Upgrading setuptools worked for me:

    pip3 install --upgrade setuptools
    
    0 讨论(0)
  • 2020-12-07 19:13

    I tried most of the above suggested solutions but nothing worked as pip3 was totally non-functional, then I found this: https://deeptalk.lambdalabs.com/t/trying-to-uninstall-tensorflow-or-matplotlib-pip-package-throws-attributeerror--namespacepath-object-has-no-attribute-sort/310

    I think this is probably the issue with most of us. I tried the suggested solution and pip3 is working again.

    For me the matplotlib was not present in dist-packages but instead it was in site-packages, so the command that worked for me was:

    sudo rm ~/.local/lib/python3.5/site-packages/matplotlib-3.0.3-py3.5-nspkg.pth
    

    ofcourse you need to change the above path based on your version and location of matplotlib.

    0 讨论(0)
  • 2020-12-07 19:14

    This is for windows users, who installed WinPython We couldn't even run pip command. Uninstall and install of Anaconda 3 We faced similar error. Finally we removed folder "Python" which is inside C:\Users\you\AppData\Roaming\ and removed folder "conda" & "packages" which is inside C:\Users\you\AppData\Roaming\conda. Then it worked.

    0 讨论(0)
  • 2020-12-07 19:16

    I met the same issue with python 3.5.2 and pip3 (9.0.1). And I fixed it by following this workaround: https://github.com/pypa/setuptools/issues/885#issuecomment-307696027

    More specifically, I edited line #2121~2122 of this file: "sudo vim /usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py"

    #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]
    
    0 讨论(0)
  • 2020-12-07 19:19

    This may sound weird, because I had this issue and I had tried everything mentioned in SO and GitHub issues. But then I installed pip with easyinstall and pip command is working. Maybe now there are 2 pip packages now. But error is gone.

    easy_install pip

    0 讨论(0)
提交回复
热议问题