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

后端 未结 16 1407
生来不讨喜
生来不讨喜 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:28

    I had this problem consistently (and used the workaround below to use pip in the python3 interpreter). To my surprise, after uninstalling all versions of numpy and reinstalling the latest one, pip began working again. I can't say for sure what happened, but it might be something to try if everything else has failed.

    The workaround (pieced together from several sources I don't recall) is

    1. start python3
    2. import pip twice (getting an error the first time)
    3. use pip.main within the interpreter

    Here is a transcript:

    >>> import pip
    Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py",
        __import__(vendored_name, globals(), locals(), level=0)
    ImportError: No module named 'pip._vendor.pkg_resources'
    
    During handling of the above exception, another exception occurred
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3/dist-packages/pip/__init__.py", line 13,
        from pip.exceptions import InstallationError, CommandError, Pi
      File "/usr/lib/python3/dist-packages/pip/exceptions.py", line 6,
        from pip._vendor.six import iteritems
      File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", l
        vendored("pkg_resources")
      File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", l
        __import__(modulename, globals(), locals(), level=0)
                                    .
                                   etc
                                    .
    AttributeError: '_NamespacePath' object has no attribute 'sort'
    >>> import pip
    >>> pkgs = ['asciiplotlib']
    >>> pip.main(['install'] + pkgs + ['--upgrade'])
    Collecting asciiplotlib
      Using cached https://files.pythonhosted.org/packages/15/c5/46a2d
    Installing collected packages: asciiplotlib
    Successfully installed asciiplotlib-0.1.8
    
    0 讨论(0)
  • 2020-12-07 19:29

    try -
    pip install -U pip
    pip install -U setuptools

    if editing __init__.py doesnt help.

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

    Try : sudo easy_install pip and then

    sudo easy_install setuptools

    It probably happends because of messed-up dependencies.

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

    I had this same problem, and was unable to run any command with pip3 (including any commands like pip3 install --upgrade pip setuptools).

    Only fix I've found was to completely uninstall and re-install python 3 (sudo apt-get remove python3, sudo apt-get install python3, sudo apt install python3-pip) and now pip3 is working properly again.

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