Python Tutorial: pip - An in-depth look at the package management system
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.
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?
What’s the typical workflow for finding, installing, and verifying a package?
How can users check whether installed packages are out of date, and upgrade them?
How does pip support reproducible dependency sharing between developers?
What workaround enables upgrading all outdated packages when pip lacks a one-command solution?
Review Questions
- What command would you run to create a requirements file that pins exact package versions for a project?
- How do `pip list` and `pip list -o` differ in what they report?
- Describe the purpose of the `cut` step in the batch-upgrade pipeline and what input/output it produces.
Key Points
- 1
Use `pip help` and `pip help <command>` to quickly find the correct options for common tasks like installation and upgrading.
- 2
Find unknown packages with `pip search`, then install with `pip install <package>` and confirm with `pip list`.
- 3
Remove dependencies using `pip uninstall <package>` and verify the change with another `pip list`.
- 4
Check for outdated dependencies using `pip list -o` / `pip list outdated`, then upgrade a single package with `pip install -U <package>`.
- 5
Create reproducible environments by generating `requirements.txt` via `pip freeze` and installing with `pip install -r requirements.txt`.
- 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
Validate the end state with `pip list outdated` to confirm no packages remain behind.