安装多版本python和pip

ubuntu18.04自带python3,但是没有python2,pip2,pip3。

sudo apt install python2.7  #安装python2.7
sudo apt install python-minimal
sudo apt install curl
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py #安装pip3
sudo python2 get-pip.py #安装pip3
sudo apt install python-testresources   #防止pip2出错
sudo apt install python3-testresources  #防止pip3出错
sudo pip3 install --upgrade pip #升级pip3
sudo pip2 install --upgrade pip #升级pip2

此时pip和python并不知道指向2还是3,需要自己修改。我们使用alias来设置别名。我要让pip和python都指向3

whereis pip
pip: /usr/local/bin/pip /usr/local/bin/pip3.6 /usr/local/bin/pip2.7
whereis python
python: /usr/bin/python2.7 /usr/bin/python2.7-config /usr/bin/python3.6m /usr/bin/python3.6 /usr/bin/python3.6m-config /usr/bin/python3.6-config /usr/bin/python /usr/lib/python2.7 /usr/lib/python3.7 /usr/lib/python3.6 /etc/python2.7 /etc/python3.6 /etc/python /usr/local/lib/python2.7 /usr/local/lib/python3.6 /usr/include/python2.7 /usr/include/python3.6m /usr/include/python3.6 /usr/share/python /usr/share/man/man1/python.1.gz

可见pip3在:

/usr/local/bin/pip3.6

python在:

/usr/bin/python3.6

自定义alias别名:

gedit ~/.bashrc

打开文件后,在最后一行加:

alias pip=/usr/local/bin/pip3.6
alias python=/usr/bin/python3.6

然后更新环境:

source ~/.bashrc

你可能感兴趣的:(安装多版本python和pip)