Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Python
Stage 5: Specialization

Part 07 / Topic 8 of 9

pip and requirements.txt

pip installs packages from PyPI (the Python Package Index, a free online store of packages). Use it inside an active venv.

Real-world example: install requests for the weather app and share the list with a teammate.

pip install requests               # install a package
pip install requests==2.32.3       # install an exact version
pip list                           # see what is installed
pip show requests                  # details of one package
pip uninstall requests             # remove it

pip freeze > requirements.txt      # save exact versions to a file
pip install -r requirements.txt    # teammate installs the same versions

A requirements.txt looks like:

certifi==2025.1.31
charset-normalizer==3.4.1
idna==3.10
requests==2.32.3
urllib3==2.3.0

You only installed requests; the other lines are its dependencies (packages it needs), which pip installed for you.

Tip: python -m pip install ... is the safest form. It uses the pip of the Python you are running.

Modern alternative: uv. uv is a very fast tool that does the job of venv + pip together:

uv venv                # create .venv
uv pip install requests
uv pip install -r requirements.txt

Learn plain venv + pip first. They are always available. Try uv later.

Error: externally-managed-environment? On many modern Linux systems (for example Ubuntu 23.04+ and Debian 12+) and with Homebrew Python on macOS, running pip install ... outside a venv stops with this error (PEP 668). Your system's Python belongs to the operating system, and pip refuses to change it. The fix is simple: create and activate a venv (section 7), then run pip install again. Do not use --break-system-packages.

๐Ÿ” Going deeper: requirements.txt is the simple, classic way. Modern projects list their direct dependencies in a pyproject.toml file and let a tool (pip, uv, Poetry) create a lock file with exact versions. Never install with sudo pip; it can break your system's own Python.

Read more: the official pip documentation.

Done here? The practice set for Part 7 โ€” 7 exercises with solutions โ€” is on the part page.

Search the guide