How to change pip3 command to be pip?

前端 未结 9 2462
梦毁少年i
梦毁少年i 2020-12-04 23:33

I uninstalled pip, and I installed pip3 instead. Now, I want to use pip3 by typing pip only. The reason is I am used to t

相关标签:
9条回答
  • 2020-12-04 23:49

    Rather than manually creating your own alias in bash and hoping this doesn't conflict with anything, most package managers should allow you to register the version you wish to use whilst maintaining dependencies.

    For instance on Linux:

    sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
    

    Or on Mac (MacPorts):

    port select --set pip pip3
    
    0 讨论(0)
  • 2020-12-04 23:51

    Pip is installed in /usr/bin/. If you don't have pip at all, I would suggest to install pip3 only. Make sure you don't need older version.

    You can check available pip versions using following command.

    ls /usr/bin/pip*

    If you have multiple pip you need to prioritize your pip versions. I had only pip3 so I add it to the first priority. You can use following command and it is done.

    sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1

    You will get output as :

    update-alternatives: using /usr/bin/pip3 to provide /usr/bin/pip (pip) in auto mode

    Test now:

    pip --version

    You will get: pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)

    If you have other version for python2.7, you can use same update command and change last digit 1 to 2. This will make it second priority.

    0 讨论(0)
  • 2020-12-04 23:52

    You can write pip for pip3 after changing bashrc file in the home directory.

    In mac -

    Open bashrc file -

    vim ~/.bashrc
    

    Add this line at the end of the file -

    alias pip="pip3"
    

    Close the file. Don't forget to source this file in the terminal by

    source ~/.bashrc
    

    You are good to go. Now, whenever you will use pip in any command. it will be interpreted as pip3

    You can check it by running the command -

    pip --version
    
    0 讨论(0)
  • 2020-12-04 23:55

    I believe one shouldn't do such a thing. Actually I would argue it's even better to not use the pip, pip3, etc. scripts ever. Instead one should always prefer the more explicit and surefire way of using pip's executable module for one specific Python interpreter:

    path/to/pythonX.Y -m pip somecommand
    

    References:

    • https://snarky.ca/why-you-should-use-python-m-pip/
    • https://snarky.ca/a-quick-and-dirty-guide-on-how-to-install-packages-for-python/
    0 讨论(0)
  • 2020-12-05 00:04

    This can be done by simply creating an alias for the command. To create an alias just type

    $alias new_command="existing_command"
    In your case,
    $alias pip="pip3"

    Although this isn't permanent. OT make it permanent edit your bashrc file
    $ vim ~/.bashrc
    an to the end of it append the line. $alias pip="pip3"

    0 讨论(0)
  • 2020-12-05 00:05

    Solution 1

    Check which version pip is pointing to

    pip --version
    pip 18.0 from /usr/lib/python2.7/site-packages/pip (python 2.7)
    

    If your pip is pointing to pip2, locate where is the pip "binary".

    which pip
    /usr/bin/pip
    

    This is a simple python script:

    cat /usr/bin/pip
    #!/usr/bin/python2
    
    # -*- coding: utf-8 -*-
    import re
    import sys
    
    from pip._internal import main
    
    if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
        sys.exit(main())
    

    So just change the shebang from #!/usr/bin/python2 to #!/usr/bin/python3.

    Now pip is pointing to pip3.

    pip --version         
    pip 18.0 from /usr/lib/python3.6/site-packages/pip (python 3.6)
    

    Solution 2

    Remove /usr/bin/pip make make a symbolic link from the wanted pip version to it instead.

    sudo rm /usr/bin/pip
    sudo ln -s /usr/bin/pip3.6 /usr/bin/pip
    
    0 讨论(0)
提交回复
热议问题