High frequency command of PIP module

When you use python, you must have used the pip command of pip module to install various three-party modules. pip is called the package manager. It is the preferred installer for Python. Through the pip command, you can download and install the packages in the remote warehouse * * Pypi * * locally.

To put it bluntly, pip is the "warehouse keeper" of wheels in Python language. Without it, you will have no wheels to use. Therefore, it is necessary for us to be familiar with the business ability of this "warehouse keeper".


Starting with Python 3.4, python has provided pip for each Python installation package.

Next, let's take a look at the capabilities of the "warehouse keeper".

1. View pip version number

pip --version

(base) mrfu@MrFus-MacBook-Pro ~ % pip --version
pip 21.2.4 from /opt/anaconda3/lib/python3.9/site-packages/pip (python 3.9)

2. Get pip help

pip help

(base) mrfu@MrFus-MacBook-Pro ~ % pip help

  pip <command> [options]

  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  cache                       Inspect and manage pip's wheel cache.
  index                       Inspect information available from package indexes.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

#Omit 100 million words here!

3. Install the third-party library

  • Normal Wheel - only contains Python files, no compiled extensions, and supports Python 2 and 3 natively.
  • Pure Python Wheel - contains only Python files without compiled extensions, but does not natively support Python 2 and 3.
  • Platform Wheel - contains Python files and compiled extensions, but does not support Python 2 and 3 itself. This type of Wheel is platform specific, such as Windows or macOS, because it contains compiled extensions.


A library can only have one version number installed in an environment, so if there is a need for multiple versions, use the virtual environment.

a. General installation

pip install library name

99% of pythoners have used this command!

b. Specify version number installation

pip install library name = version number

Sometimes the lower version of the library is better, so these commands are also useful.

c. Install whl file

pip install xxx.whl

The WHL file is a python installation package saved in Wheel format, which is a standard built-in package format for Python distributions. The WHL file contains all the files and metadata installed by python, including the Wheel version used and the packaged specification. WHL files are compressed using Zip compression, which is actually a compressed file.

The wheel format was defined by PEP 427 in 2012, replacing the original one Egginstallation package format. Wheel supports the installation process without compilation, which is faster and more reliable, and supports offline installation. Wheel is now considered the standard format for Python binary packages.

There are three types of WHL files:

d. Upgrade pip version

pip install --upgrade pip

When installing a third-party library, you will often be prompted:

WARNING: You are using pip version 21.3.1; however, version 22.1 is available.
You should consider upgrading via the '/Users/mrfu/Desktop/MacFiles/Pythonenv/venv/bin/python -m pip install --upgrade pip' command.

This is because the version of your pip is not the latest. Just follow the prompts to upgrade.

1. Libraries used for batch export projects

pip freeze > requirements.txt

When a Python project is rebuilt in another environment, it often does not have a relatively complete dependent package for the required running environment. However, we are not sure what package is missing. It is very troublesome to see what the program is written, so there are requirements Txt file. We can use the command to batch export the installed library name and version number from the original project to the manifest file requirements Txt.

Requirements Txt file contents are as follows:


2. Batch installation Library

pip install -r requirements.txt

The above command can set requirements Txt file.

3. Uninstall installed Libraries

pip uninstall library name

4,pip list

a. View installed Libraries

(venv) (base) mrfu@MrFus-MacBook-Pro Pythonenv % pip list
Package            Version
------------------ -----------
async-generator    1.10
attrs              21.4.0
beautifulsoup4     4.11.1
certifi            2021.10.8
cffi               1.15.0
charset-normalizer 2.0.12
cryptography       37.0.2
h11                0.13.0

b. View updatable Libraries

(venv) (base) mrfu@MrFus-MacBook-Pro Pythonenv % pip list -o
Package    Version Latest Type
---------- ------- ------ -----
pip        21.3.1  22.1   wheel
setuptools 60.2.0  62.3.1 wheel

Tags: Python pip

Posted by papaface on Tue, 31 May 2022 13:25:45 +0530