Python Programming from First Principles: Learn to Code, Think Computationally, and Solve Real-World Problems
PDFEPUB
BOOK 000 · CHAPTER 6 · Python PIP

Python PIP

On this pageCheck the interpreterInstall and inspect a packageRecord dependencies

Python includes a standard library. When a program needs another package, use pip to install it into the Python environment that runs the program.

Check the interpreter

A notebook kernel may use a different interpreter from your terminal. Inspect its executable before installing packages.

import sys
print(sys.executable)
print(sys.version)
Listing 266 — Check the interpreter

Output

/opt/anaconda3/bin/python
3.13.5 | packaged by Anaconda, Inc. | (main, Jun 12 2025, 11:23:37) [Clang 14.0.6 ]

Install and inspect a package

Run these commands in a terminal with your chosen environment active:

python -m pip --version
python -m pip install requests
python -m pip show requests
python -m pip list
Listing 267 — Install and inspect a package

python -m pip uses pip belonging to that interpreter. After installation, a Python program imports the package with import requests. The package name used for installation and the import name are not always identical.

Record dependencies

python -m pip freeze > requirements.txt
python -m pip install -r requirements.txt
Listing 268 — Record dependencies

The first command records installed versions. The second installs the recorded requirements in another environment. Keep the requirements with the project. Recreate the environment rather than copying its directory between computers.

Reference: pip user guide, checked 20 October 2026.