liveBook · Manning

Requirements.txt

As explained in Build Python Web Apps with Streamlit

requirements.txt is a conventionally named file that lists Python modules and compatible version specifications required by an application.

A requirements.txt file records the Python modules an application needs and the versions compatible with its code. Each line names a module, optionally followed by an exact version or minimum version. Passing the file to pip installs the listed dependencies, helping development and production environments behave consistently. section 5.4.1

Use requirements.txt to manage dependencies during deployment:

  • List external modules such as requests and streamlit. section 5.4.1
  • Pin exact versions when code depends on specific behavior, such as requests==2.31.0. section 5.4.1
  • Use minimum versions such as requests>=2.31.0 when later releases remain acceptable. section 5.4.1
  • Install everything with pip install -r requirements.txt. section 5.0
  • Add the file to a GitHub repository so Streamlit Community Cloud can install the application libraries automatically. section 5.4.1

Creating the file

For an application using only requests and streamlit, start with those two module names. Inspect installed versions with pip show, or generate a file from the development environment with pip freeze > requirements.txt. Review generated output because it includes every installed package, not only the application’s direct dependencies. section 5.4.1

Listing 5.5 A strict requirements.txt file
requests==2.31.0
streamlit==1.34.0

The strict example shows how exact versions make the deployment environment reproducible: requests==2.31.0 and streamlit==1.34.0. section 5.4.1

How Build Python Web Apps with Streamlit covers it

How deep it goes
Defines module lines, exact versions, version ranges, pip installation, and automatic cloud installation, but not dependency resolution internals.
Examples
Uses requests and streamlit listings, pip show, pip freeze, exact pins, minimum versions, and a cloud deployment file.
What it assumes
Assumes basic Python imports and terminal use while teaching dependency listing, version pinning, and pip installation directly.
What you can do after
Operate/configure pip installations and Streamlit Community Cloud deployments with declared Python dependencies.
How it connects
Connects Python modules, pip, dependency management, development environments, production environments, GitHub, and deployment.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.