Error after upgrading pip: cannot import name 'main'

后端 未结 30 1700
清歌不尽
清歌不尽 2020-11-22 15:51

Whenever I am trying to install any package using pip, I am getting this import error:

guru@guru-notebook:~$ pip3 install numpy
Traceback (most recent call l         


        
相关标签:
30条回答
  • 2020-11-22 16:30

    import main from pip._internal

    from pip._internal import main
    

    Edit the pip code from

    sudo nano /usr/bin/pip3
    
    0 讨论(0)
  • 2020-11-22 16:30

    Use the following command before the execution of any pip command

    hash -d pip
    

    It will work

    0 讨论(0)
  • 2020-11-22 16:31

    What worked for me to fix the error with using pip3 was:

    sudo cp -v /usr/local/bin/pip3 /usr/bin/pip3

    Everything works:

     demon@UbuntuHP:~$ pip -V
     pip 10.0.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
    
     demon@UbuntuHP:~$ pip2 -V
     pip 10.0.1 from /home/demon/.local/lib/python2.7/site-packages/pip (python 2.7)
    
     demon@UbuntuHP:~$ pip3 -V
     pip 10.0.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
    

    Maybe the new 10.0.1 version of pip doesn't update the binary in /usr/bin ? (which seems it does not)

    EDIT: the same issue occurs in Ubuntu 18.04. The best solution I've found is to symlink the pip binaries from /home/<user/.local/bin to /usr/local/bin or /usr/bin (depending on your preference), as follows:

    ln -sv /home/<user>/.local/bin/pip /usr/local/bin/pip
    ln -sv /home/<user>/.local/bin/pip2 /usr/local/bin/pip2
    ln -sv /home/<user>/.local/bin/pip2.7 /usr/local/bin/pip2.7
    ln -sv /home/<user>/.local/bin/pip3 /usr/local/bin/pip3
    ln -sv /home/<user>/.local/bin/pip3.6 /usr/local/bin/pip3.6
    
    

    NOTE: replace <user> with your current running user

    The associated versions (latest) are in:

    Version 3.6:

    /home/demon/.local/lib/python3.6/site-packages/pip (python 3.6)

    Version 2.7:

    /home/demon/.local/lib/python2.7/site-packages/pip (python 2.7)

    0 讨论(0)
  • 2020-11-22 16:31

    Is something wrong with the packages, when it generating de file /usr/bin/pip, you have to change the import:

    from pip import main
    

    to

    from pip._internal import main
    

    That solves the problem, I'm not sure why it generated, but it saids somthing in the following issue:

    After pip 10 upgrade on pyenv "ImportError: cannot import name 'main'"

    0 讨论(0)
  • 2020-11-22 16:32

    On Debian you will need to update apt first....

    sudo apt-get update -qq
    sudo apt-get install python-pip -qq
    sudo pip install pip --upgrade --quiet
    sudo pip2 install virtualenv --quiet
    

    If you skip 'sudo apt-get update -qq' your pip will become corrupt and display the 'cannot find main' error.

    0 讨论(0)
  • 2020-11-22 16:33

    This error may be a permission one. So, test executing the command with -H flag:

    sudo -H pip3 install numpy
    
    0 讨论(0)
提交回复
热议问题