Generating a requirements.txt file is the best way to ensure your cPanel environment matches your local development setup. There are two main ways to do it, depending on how you’ve managed your project so far.
Option 1: The “Quick & Dirty” Way
If you are working inside a virtual environment (which you should be!), you can generate the file automatically using pip.
- Open your terminal/command prompt in your project folder.
- Activate your virtual environment.
- Run the following command:Bash
pip freeze > requirements.txt
NB: If you run this outside of a virtual environment,
pip freezewill list every single Python package installed on your entire computer. This will make your cPanel deployment very bloated and likely cause errors.
Option 2: The “Clean” Way (Recommended)
If you haven’t been using a virtual environment, or if your environment is cluttered, use a tool called pipreqs. Unlike pip freeze, it looks at your code and only lists the packages you actually import.
- Install pipreqs:
pip install pipreqs - Run it in your project folder:
pipreqs . --force- The
.tells it to look in the current folder, and--forceoverwrites any existing file.
- The
Staff Writer
