Get AI summaries of any video or article — Sign up free
Python Tutorial: pip - An in-depth look at the package management system thumbnail

Python Tutorial: pip - An in-depth look at the package management system

Corey Schafer·
4 min read

Based on Corey Schafer's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Use `pip help` and `pip help <command>` to quickly find the correct options for common tasks like installation and upgrading.

Briefing

pip is the go-to command-line tool for installing, removing, and tracking Python packages, and the fastest way to get productive is to start with its built-in help, then use a small set of core commands: search, install, list, uninstall, and upgrade. The walkthrough begins by pointing to `pip help`, which prints available commands and options, and then shows how `pip help <command>` narrows the output to a specific task like `install`.

From there, the workflow moves through day-to-day package management. When the exact package name isn’t known, `pip search` returns matching package names along with short descriptions, letting users choose what to install. Installation is done with `pip install <package>`, and success is confirmed by running `pip list`, which displays installed packages and their version numbers. Removing a dependency uses `pip uninstall <package>`, followed by confirmation, and another `pip list` verifies the package is gone.

Version awareness is treated as a first-class concern. To check whether installed packages are behind, the tutorial uses `pip list -o` (or `pip list outdated`), which flags packages that aren’t on the latest available release. A concrete example is `setuptools`, where the installed version is compared against the latest version; upgrading is handled with `pip install -U <package>`, after which `pip list` confirms the version bump.

The practical problem of sharing dependencies is solved with `pip freeze`. Instead of manually copying a long list from `pip list`, `pip freeze` outputs all installed packages and versions in a requirements-style format. Redirecting that output into `requirements.txt` creates a portable dependency manifest. Another developer can then install the exact same set of packages by running `pip install -r requirements.txt`, which reads the file and installs each package at the pinned version.

Finally, the tutorial addresses a common pain point: updating many packages at once. While `pip` doesn’t provide a simple built-in “upgrade everything that’s outdated” command, a workaround from Stack Overflow chains together shell tools. The approach starts with `pip freeze` to generate requirements, filters out lines using `grep`, extracts only the package names with `cut` (splitting on `=`), and then loops through those names to run `pip install -U <package>` for each one. After the batch upgrade, `pip list outdated` returns no results, indicating the environment is fully up to date.

Cornell Notes

pip manages Python packages through a small set of repeatable commands: `pip search` to find packages, `pip install` to add them, `pip list` to see what’s installed, and `pip uninstall` to remove dependencies. Version tracking is handled with `pip list -o` / `pip list outdated`, and upgrades for a single package use `pip install -U <package>`. For sharing environments, `pip freeze` writes installed packages and exact versions into a requirements-style file (e.g., `requirements.txt`), and `pip install -r requirements.txt` recreates the same dependency set. When many packages need updates, a shell pipeline can transform `pip freeze` output into package names and run `pip install -U` across them, then `pip list outdated` verifies the result.

How does a user discover the right pip commands and options quickly?

Start with `pip help`, which lists the main commands (including install, uninstall, freeze) and general options. For more targeted guidance, use `pip help <command>`—for example, `pip help install` shows the specific options available for installation, such as using a requirements file (`-r`), upgrading (`-U`), and installing per-user.

What’s the typical workflow for finding, installing, and verifying a package?

If the package name is unknown, run `pip search <term>` to get matching package names and descriptions. Install the chosen package with `pip install <package>`. Then verify installation with `pip list`, which shows installed packages along with their version numbers. Uninstall uses `pip uninstall <package>` and confirmation, followed by another `pip list` to confirm it’s removed.

How can users check whether installed packages are out of date, and upgrade them?

Use `pip list -o` (or `pip list outdated`) to list packages that aren’t on the latest version. For upgrades, run `pip install -U <package>` (uppercase U) to upgrade that specific package. After upgrading, `pip list` should show the updated version.

How does pip support reproducible dependency sharing between developers?

Use `pip freeze` to output all installed packages and versions in requirements format. Redirect it into a file like `requirements.txt`, then share that file. Another developer installs the same pinned dependencies using `pip install -r requirements.txt`, which reads the file and installs each package at the exact version listed.

What workaround enables upgrading all outdated packages when pip lacks a one-command solution?

A chained command uses `pip freeze` to generate requirements, pipes through `grep` to filter out unwanted lines (such as package definitions), uses `cut` with `=` as the delimiter to extract only package names, and then feeds those names into `pip install -U <package>` one by one. After running the batch upgrade, `pip list outdated` should return no packages needing updates.

Review Questions

  1. What command would you run to create a requirements file that pins exact package versions for a project?
  2. How do `pip list` and `pip list -o` differ in what they report?
  3. Describe the purpose of the `cut` step in the batch-upgrade pipeline and what input/output it produces.

Key Points

  1. 1

    Use `pip help` and `pip help <command>` to quickly find the correct options for common tasks like installation and upgrading.

  2. 2

    Find unknown packages with `pip search`, then install with `pip install <package>` and confirm with `pip list`.

  3. 3

    Remove dependencies using `pip uninstall <package>` and verify the change with another `pip list`.

  4. 4

    Check for outdated dependencies using `pip list -o` / `pip list outdated`, then upgrade a single package with `pip install -U <package>`.

  5. 5

    Create reproducible environments by generating `requirements.txt` via `pip freeze` and installing with `pip install -r requirements.txt`.

  6. 6

    When needing to upgrade many outdated packages, use a shell pipeline that extracts package names from `pip freeze` output and runs `pip install -U` for each one.

  7. 7

    Validate the end state with `pip list outdated` to confirm no packages remain behind.

Highlights

`pip freeze` turns an environment’s installed packages into a requirements-style file so others can recreate the same dependency set exactly.
`pip list -o` / `pip list outdated` provides a direct way to identify which installed packages lag behind the latest releases.
A batch upgrade workaround chains `pip freeze` with `grep` and `cut` to generate package names, then upgrades each with `pip install -U`.

Topics

  • Pip Help
  • Package Install
  • Version Outdated
  • Requirements Files
  • Batch Upgrades