pip
pip is the standard and default package manager for Python. It allows you to download, install, and manage Python libraries and dependencies from the Python Package Index (PyPI) and other repositories.
Installation and Setup
pip is included by default with CPython distributions since version 3.4. To ensure you have the latest versions of pip, you can run:
$ python -m pip install --upgrade pip
If pip is not available in your Python installation, then you can run the following:
$ python -m ensurepip --upgrade
Key Features
- Installs Python packages and their required dependencies from PyPI or other package indices.
- Supports installing packages from various sources, including Git repositories, ZIP files, wheel files, and local directories.
- Enables users to specify exact package versions or define version ranges.
- Facilitates environment replication by installing dependencies listed in a
requirements.txtfile. - Provides commands to list installed packages (
pip list), view package metadata (pip show), and upgrade or uninstall existing packages.
Usage
Install the latest version of a package:
$ python -m pip install package-name
Install specific versions of a package:
$ # Exact version: ==
$ python -m pip install "package-name==version"
$ # At least version: >=
$ python -m pip install "package-name>=version"
$ # Less than version: <
$ python -m pip install "package-name<version"
Capture the environment:
$ python -m pip freeze > requirements.txt
Replicate the environment:
$ python -m pip install -r requirements.txt
Related Resources
Tutorial
Using Python's pip to Manage Your Projects' Dependencies
What is pip? In this beginner-friendly tutorial, you'll learn how to use pip, the standard package manager for Python, so that you can install and manage packages that aren't part of the Python standard library.
For additional information on related topics, take a look at the following resources: