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
