Reputation: 211
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
Upvotes: 10
Views: 23737
Reputation: 3258
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)
Upvotes: 11
Reputation: 7130
A very intuitive and straightforward method is just modify the settings in /usr/local/bin/pip
. You don't need alias and symbolic links. For mine:
lerner@lerner:~/$ pip -V
pip 1.5.4 from /usr/lib/python3/dist-packages (python 3.4)
lerner@lerner:~/$ pip2 -V
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
lerner@lerner:~/$ whereis pip
pip: /usr/local/bin/pip3.4 /usr/local/bin/pip2.7 /usr/local/bin/pip
Change the python3 to python2, be careful of its version(1.5.4 to 9.0.1 everywhere). And I just change the pip file to this:
lerner@lerner:~/$ sudo vim /usr/local/bin/pip
#!/usr/bin/python2 # EASY-INSTALL-ENTRY-SCRIPT: 'pip==9.0.1','console_scripts','pip' __requires__ = 'pip==9.0.1' import sys from pkg_resources import load_entry_point if __name__ == '__main__': sys.exit( load_entry_point('pip==9.0.1', 'console_scripts', 'pip')() )
lerner@lerner:~/$ pip -V
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
Done.
Upvotes: 0
Reputation: 11477
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.
Upvotes: 5