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, runningpip 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 runpip installagain. Do not use--break-system-packages.
๐ Going deeper:
requirements.txtis the simple, classic way. Modern projects list their direct dependencies in apyproject.tomlfile and let a tool (pip, uv, Poetry) create a lock file with exact versions. Never install withsudo 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.