pip

A package manager in the Python programming language for installing and managing third-party Python modules

grammar

pip <command> [options]

Options

Order

install installation package.
download download package.
uninstall uninstalls the package.
freeze outputs installed packages in requirements format.
inspect inspects the Python environment.
list lists installed packages.
show displays information about installed packages.
check Verifies that installed packages have compatible dependencies.
config manages local and global configuration.
search Search for packages on PyPI.
cache inspects and manages pip's wheel cache.
index examines information obtained from the package index.
wheel Build wheels from your requirements.
hash Calculates the hash value of the package archive.
completion Auxiliary command for command completion.
debug displays useful information for debugging.
help Displays help information for the command.

General options

-h, --help Display help.
--debug allows unhandled exceptions to propagate outside the main subroutine instead of logging them to stderr.
--isolated Run pip in isolated mode, ignoring environment variables and user configuration.
--require-virtualenv Allow pip to run only in a virtual environment; otherwise exit with an error.
--python <python> Run pip using the specified Python interpreter.
-v, --verbose Provide more output. This option is stackable and can be used up to 3 times.
-V, --version Display version and exit.
-q, --quiet Provide less output. This option is stackable and can be used up to 3 times (corresponding to WARNING, ERROR and CRITICAL log levels).
--log <path> Path to append logs to.
--no-input Disable input prompts.
--keyring-provider <keyring_provider>
                             If user input is allowed, enables credential lookup through the keyring library. Specify the mechanism to use [disabled, import, subprocess]. (Default: disabled)
--proxy <proxy> specifies the proxy in the format of scheme://[user:passwd@]proxy.server:port.
--retries <retries> The maximum number of times each connection should be attempted (default 5).
--timeout <sec> Set socket timeout (default 15 seconds).
--exists-action <action> Default action when path already exists: (s) switch, (i) ignore, (w) erase, (b) backup, (a) abort.
--trusted-host <hostname> Mark this host or host:port pair as trusted even if it does not have valid or any HTTPS.
--cert <path> Path to the PEM-encoded CA certificate package. If provided, the default value will be overridden. See 'SSL Certificate Verification' in the pip documentation for more information.
--client-cert <path> Path to the SSL client certificate, a single file containing the private key and certificate in PEM format.
--cache-dir <dir> Store cache data in <dir>.
--no-cache-dir disables caching.
--disable-pip-version-check
                             Occasionally check PyPI to see if there is a new version of pip available for download. Implicit with --no-index.
--no-color Suppress colored output.
--no-python-version-warning
                             Silent deprecation warnings for Python that will soon be unsupported.
--use-feature <feature> Enable new features that may not be backwards compatible.
--use-deprecated <feature> Enable deprecated features that will be removed in the future.

Install

Pip is a package management tool for Python that is usually installed with Python installation. Make sure your Python version is 3.4 or higher.

# Ubuntu system
sudo apt install python3-pip
#CentOS
sudo yum install python3-pip

If you need to update Pip, you can run the following command:

python -m pip install --upgrade pip

Check if pip is installed

pip --version

Make sure you are using the latest version of pip, you can upgrade by running the following command

python -m pip install --upgrade pip

Installation package

Installing Python packages via Pip is very simple. Use the following command:

pip install <package_name>

For example, install a package called requests:

pip install requests

Uninstall package

To uninstall an installed package, use the following command:

pip uninstall package_name

For example, to uninstall the requests package:

pip uninstall requests

View installed packages

You can use the following command to view all installed packages and their versions in the current environment:

pip list

Export and import dependencies

Use the pip freeze command to export all packages and their versions in the current environment to a text file, usually named requirements.txt:

pip freeze > requirements.txt

To install the same dependencies in another environment, you can use the following command:

pip install -r requirements.txt

Install a specific version of a package

If you need to install a specific version of a package, you can add the version number after the package name:

pip install package_name==1.2.3

Search package

To search for available Python packages, you can use the pip search command:

pip search package_name

Install development version

Sometimes you may need to install the development version of a package. Typically, development versions are stored in a version control system (such as GitHub):

pip install git+https://github.com/user/repo.git

This will install the latest version of the repository.

The above are some commonly used Pip commands. I hope this brief tutorial can help you better use the Python package management tool.

Official website

For more installation and usage methods, you can visit the official website to learn: https://pypi.org/project/pip/