Generating a requirements.txt file for your cPanel environment

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.

  1. Open your terminal/command prompt in your project folder.
  2. Activate your virtual environment.
  3. Run the following command:Bashpip freeze > requirements.txt

NB: If you run this outside of a virtual environment, pip freeze will 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.

  1. Install pipreqs: pip install pipreqs
  2. Run it in your project folder: pipreqs . --force
    • The . tells it to look in the current folder, and --force overwrites any existing file.

Posted in CPanel, Knowledgebase, Web and Email Hosting

Staff Writer