Using a requirements.txt file is a great approach for managing dependencies, especially for sharing your project or deploying it. Here’s how you can do it:
1. Create requirements.txt File
List all dependencies in the requirements.txt file. Here’s an example based on your multi-page Streamlit app:
streamlit
openai
langchain
whisper
matplotlib
pandas
plotly
seaborn
altair
Add any additional libraries your app might need.
2. Install Dependencies from requirements.txt
To install all packages listed in requirements.txt, use the following command from within your virtual environment:
pip install -r requirements.txt
3. Generate requirements.txt Automatically (Optional)
If you’ve already installed packages in your environment, you can generate a requirements.txt file automatically by running:
pip freeze > requirements.txt
This will include exact versions of all packages installed, ensuring consistency across different environments.
4. Version Pinning (Optional but Recommended)
To ensure compatibility, pin specific versions for each package in requirements.txt. For example:
streamlit==1.25.0
openai==0.27.0
langchain==0.0.205
whisper==1.0.0
matplotlib==3.8.0
pandas==2.2.2
plotly==5.15.0
seaborn==0.12.0
altair==4.2.2
Pinning versions can prevent issues that may arise from incompatible package updates.
Using requirements.txt is an excellent way to manage dependencies for larger projects or when working with multiple environments.
