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
Course
Working With Python Virtual Environments
This course demonstrates how Python's virtual environments work as a "sandbox" and you get a quick walkthrough on how to set up a new environment (or virtualenv, as they're called for short) and how to install third-party packages into it using the pip command.
For additional information on related topics, take a look at the following resources:
- Using Python's pip to Manage Your Projects' Dependencies (Tutorial)
- uv vs pip: Managing Python Packages and Dependencies (Tutorial)
- A Beginner's Guide to pip (Course)
- uv vs pip: Python Packaging and Dependency Management (Course)
- How to Publish an Open-Source Python Package to PyPI (Tutorial)
- Python Virtual Environments: A Primer (Tutorial)
- How to Manage Python Projects With pyproject.toml (Tutorial)
- Using Python's pip to Manage Your Projects' Dependencies (Quiz)
- uv vs pip: Managing Python Packages and Dependencies (Quiz)
- How to Publish Your Own Python Package to PyPI (Course)
- Publishing Python Packages to PyPI (Course)
- How to Publish an Open-Source Python Package to PyPI (Quiz)
- Python Virtual Environments: A Primer (Quiz)
- Everyday Project Packaging With pyproject.toml (Course)
- How to Manage Python Projects With pyproject.toml (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.