pip is a Python package management tool that provides the functionality to search, download, install, and uninstall Python packages.

Currently, if you arepython.orgdownloading the latest version of the installation package, then it already comes with this tool.

Note: Python 2.7.9+ or Python 3.4+ and above versions all come with the pip tool.

pip official website:https://pypi.org/project/pip/

You can use the following command to check whether it is installed:

pip --version     # Python2.x 版本命令
pip3 --version    # Python3.x 版本命令

If you haven't installed it yet, you can use the following method to install it:

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py   # 下载安装脚本
$ sudo python get-pip.py    # 运行安装脚本

Note:Whichever version of Python runs the installation script, pip will be associated with that version. If it is Python3, execute the following command:

$ sudo python3 get-pip.py    # 运行安装脚本。

Generally, pip corresponds to Python 2.7, and pip3 corresponds to Python 3.x.

Some Linux distributions can directly install pip using the package manager, such as Debian and Ubuntu:

sudo apt-get install python-pip

pip Most Commonly Used Commands

Show version and path

pip --version

Get help

pip --help

Upgrade pip

pip install -U pip

If there is a problem with this upgrade command, you can use the following command:

sudo easy_install --upgrade pip

Install packages

pip install SomePackage              # 最新版本
pip install SomePackage==1.0.4       # 指定版本
pip install 'SomePackage>=1.0.4'     # 最小版本

For example, if I want to install Django, I can use just the following command — it is convenient and fast.

pip install Django==1.7

Upgrade packages

pip install --upgrade SomePackage

To upgrade a specified package, specify a version number using ==, >=, <=, >, <.

Uninstall packages

pip uninstall SomePackage

Search for packages

pip search SomePackage

Show installed package information

pip show 

View detailed information about a specified package

pip show -f SomePackage

List installed packages

pip list

View upgradeable packages

pip list -o

pip Upgrade

Linux or macOS

 
pip install --upgrade pip    # python2.x
pip3 install --upgrade pip   # python3.x

Windows platform upgrade:

python -m pip install -U pip   # python2.x
python -m pip3 install -U pip    # python3.x

pip Tsinghua University Open Source Software Mirror

Using a domestic mirror will be much faster:

Temporary use:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

For example, install Django:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Django

To set it as the default, you need to upgrade pip to the latest version (>=10.0.0) and then configure it:

pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

If your network connection to the pip default source is poor, temporarily use this mirror site to upgrade pip:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U

Notes

If both Python2 and Python3 have pip, use it as follows:

Python2:

python2 -m pip install XXX

Python3:

python3 -m pip install XXX