Linux / Mac / Windows 安装/配置/使用pip

安装

1
2
3
4
5
6
curl curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
python3 get-pip.py

# 部分Linux可以通过包管理器
sudo apt-get install python-pip

配置国内源

UNIX

1
2
3
4
5
vim ~/.pip/pip.conf
[global]
index-url = https://mirrors.aliyun.com/pypi/simple
[install]
trusted-host = https://mirrors.aliyun.com

NT

1
2
3
4
5
6
md %HOMEPATH%\pip
touch %HOMEPATH%\pip\pip.ini
[global]
index-url = https://mirrors.aliyun.com/pypi/simple
[install]
trusted-host = https://mirrors.aliyun.com

用法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
pip --version
pip3 --version
pip --help

# 升级pip
pip install -U pip
sudo easy_install --upgrade pip
python -m pip install -U pip

pip install package
pip install package==version
pip install package>=version
python2 -m pip install package
python3 -m pip install package
pip install --upgrade package
pip uninstall package

pip search pacakge

# 显示安装包信息
pip show

# 查看指定包的详细信息
pip show -f package

# 列出已安装的包
pip list

# 查看可升级的包
pip list -o

Reference