Change default Ubuntu pip to pip2.7

16,645

Solution 1

Concise Answer

1.  Locate pip:

$ which pip
/usr/local/bin/pip

2.  List all pips in location learned above:

$ ls /usr/local/bin/pip*
/usr/local/bin/pip   /usr/local/bin/pip2.7  /usr/local/bin/pip3.5
/usr/local/bin/pip2  /usr/local/bin/pip3

3.  Select which one should be your default, i.e. /usr/local/bin/pip2.7, and copy it into pip:

$ sudo cp /usr/local/bin/pip2.7 /usr/local/bin/pip

Verify:

$ pip -V
pip 10.0.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

Solution 2

  • You can use alias pip = 'pip2.7'Put this in your .bashrc file(If you're using bash,if zsh it should be .zshrc).

    By the way,you should know that sudo command change current user,default root.So if you have to change user to root,maybe you should put it in /root/.bashrc

  • Or you can make a link

    ln -s /usr/local/bin/pip2.7 /usr/local/bin/pip
    

Also you can try to use virtualenv,it's the best choice for multiple versions in my opinion.

Share:
16,645

Related videos on Youtube

Andres
Author by

Andres

Updated on September 15, 2022

Comments

  • Andres
    Andres over 1 year

    As the title says, is there a way to change the default pip to pip2.7

    When I run sudo which pip, I get /usr/local/bin/pip

    When I run sudo pip -V, I get pip 1.5.6 from /usr/lib/python3/dist-packages (python 3.4)

    If there is no problem at all with this mixed version, please do tell. If there is a problem with downloading dependencies from different pip versions, how can I change to pip2.7?

    I know I can pip2.7 install somePackage but I don't like it. I feel I could forget to do this at any point.

    Other info: Ubuntu 15.10

  • Carl Smith
    Carl Smith about 4 years
    In step #3 I suggset making a symlink (sudo rm /usr/local/bin/pip; sudo ln -s /usr/local/bin/pip2.7 /usr/local/bin/pip) instead of the cp because 1) there's no need to duplicate the data and moreover 2) with the cp approach the pip in your path will not reflect any changes to /usr/local/bin/pip2.7 e.g. trying to remove it.